Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeoareamonitorinfo.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include <QGeoAreaMonitorInfo>
5#include <QDateTime>
6#include <QSharedData>
7#include <QUuid>
8#include <QDataStream>
9
10#ifndef QT_NO_DEBUG_STREAM
11#include <QDebug>
12#endif
13
14QT_BEGIN_NAMESPACE
15
16QT_IMPL_METATYPE_EXTERN(QGeoAreaMonitorInfo)
17
18/*!
19 \class QGeoAreaMonitorInfo
20 \inmodule QtPositioning
21 \since 5.2
22 \ingroup QtPositioning-positioning
23 \ingroup shared
24
25 \brief The QGeoAreaMonitorInfo class describes the parameters of an area or region
26 to be monitored for proximity.
27
28 The purpose of area monitoring is to inform a user when he/she comes close to an area of
29 interest. In general such an area is described by a \l QGeoCircle. The circle's center
30 represents the place of interest and the area around it identifies the geographical region
31 within which notifications are sent.
32
33 A QGeoAreaMonitorInfo object is valid if it has a non-empty name and a valid \l area().
34 Such objects must be registered with a \l QGeoAreaMonitorSource to start and stop the
35 monitoring process. Note that extensive monitoring can be very resource consuming
36 because the positioning engine must remain active and has to match the current position
37 with each QGeoAreaMonitorInfo instance.
38
39 To further reduce the burden on the system there are optional attributes which can
40 set. Each monitored area can have an expiry date which automatically removes the
41 to-be-monitored area from the monitoring source once the expiry date has been reached.
42 Another option is to adjust the persistence of a monitored area. A QGeoAreaMonitorInfo
43 that \l isPersistent() will remain active beyond
44 the current applications lifetime. If an area is entered while the monitoring
45 application is not running the application will be started. Note that this feature is
46 not available on all platforms. Its availability can be checked via
47 \l QGeoAreaMonitorSource::supportedAreaMonitorFeatures().
48
49 \sa QGeoAreaMonitorSource
50
51 */
52
54{
55public:
59 {
60 uid = other.uid;
61 name = other.name;
62 shape = other.shape;
64 notificationParameters = other.notificationParameters;
65 expiry = other.expiry;
66 }
68
75};
76
77/*!
78 Constructs a QGeoAreaMonitorInfo object with the specified \a name.
79
80 \sa name()
81 */
82QGeoAreaMonitorInfo::QGeoAreaMonitorInfo(const QString &name)
83{
84 d = new QGeoAreaMonitorInfoPrivate;
85 d->name = name;
86 d->uid = QUuid::createUuid();
87}
88
89/*!
90 Constructs a QGeoAreaMonitorInfo object as a copy of \a other.
91 */
92QGeoAreaMonitorInfo::QGeoAreaMonitorInfo(const QGeoAreaMonitorInfo &other)
93 : d(other.d)
94{
95}
96
97/*!
98 \fn QGeoAreaMonitorInfo::QGeoAreaMonitorInfo(QGeoAreaMonitorInfo &&other) noexcept
99 \since 6.2
100
101 Constructs a QGeoAreaMonitorInfo object by moving from \a other.
102
103 Note that a moved-from QGeoAreaMonitorInfo can only be destroyed or
104 assigned to. The effect of calling other functions than the destructor
105 or one of the assignment operators is undefined.
106*/
107
108/*!
109 Destructor
110 */
111QGeoAreaMonitorInfo::~QGeoAreaMonitorInfo()
112{
113}
114
115QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QGeoAreaMonitorInfoPrivate)
116
117/*!
118 Assigns \a other to this QGeoAreaMonitorInfo object and returns a reference
119 to this QGeoAreaMonitorInfo object.
120 */
121QGeoAreaMonitorInfo &QGeoAreaMonitorInfo::operator=(const QGeoAreaMonitorInfo &other)
122{
123 d = other.d;
124 return *this;
125}
126
127/*!
128 \fn QGeoAreaMonitorInfo &QGeoAreaMonitorInfo::operator=(QGeoAreaMonitorInfo &&other) noexcept
129 \since 6.2
130
131 Move-assigns \a other to this QGeoAreaMonitorInfo object and returns a
132 reference to this QGeoAreaMonitorInfo object.
133
134 Note that a moved-from QGeoAreaMonitorInfo can only be destroyed or
135 assigned to. The effect of calling other functions than the destructor
136 or one of the assignment operators is undefined.
137*/
138
139/*!
140 \fn bool QGeoAreaMonitorInfo::operator==(const QGeoAreaMonitorInfo &lhs, const QGeoAreaMonitorInfo &rhs)
141
142 Returns \c true if all of the \a lhs object's values are the same as those
143 of \a rhs object. Otherwise returns \c false.
144*/
145
146/*!
147 \fn bool QGeoAreaMonitorInfo::operator!=(const QGeoAreaMonitorInfo &lhs, const QGeoAreaMonitorInfo &rhs)
148
149 Returns \c true if any of the \a lhs object's values are not the same as
150 those of \a rhs object. Otherwise returns \c false.
151*/
152
153/*!
154 \fn void QGeoAreaMonitorInfo::swap(QGeoAreaMonitorInfo &other)
155 \since 6.2
156 \memberswap{QGeoAreaMonitorInfo object}
157*/
158
159/*!
160 Returns the name of the QGeoAreaMonitorInfo object. The name should be used
161 for user-visibility purposes.
162 */
163QString QGeoAreaMonitorInfo::name() const
164{
165 return d->name;
166}
167
168/*!
169 Sets the user visibile \a name.
170 */
171void QGeoAreaMonitorInfo::setName(const QString &name)
172{
173 if (d->name != name) {
174 d.detach();
175 d->name = name;
176 }
177}
178
179/*!
180 Returns the identifier of the QGeoAreaMonitorInfo object.
181 The identifier is automatically generated upon construction of a new
182 QGeoAreaMonitorInfo object.
183*/
184
185QString QGeoAreaMonitorInfo::identifier() const
186{
187 return d->uid.toString();
188}
189
190/*!
191 Returns true, if the monitor is valid. A valid QGeoAreaMonitorInfo has a non-empty name()
192 and the monitored area is not \l {QGeoShape::isEmpty()}{empty()}.
193 Otherwise this function returns false.
194 */
195bool QGeoAreaMonitorInfo::isValid() const
196{
197 return (!d->name.isEmpty() && !d->shape.isEmpty());
198}
199
200/*!
201 Returns the boundaries of the to-be-monitored area. This area must not be empty.
202
203 \sa setArea()
204 */
205QGeoShape QGeoAreaMonitorInfo::area() const
206{
207 return d->shape;
208}
209
210/*!
211 Sets the to-be-monitored area to \a newShape.
212
213 \sa area()
214 */
215void QGeoAreaMonitorInfo::setArea(const QGeoShape &newShape)
216{
217 d.detach();
218 d->shape = newShape;
219}
220
221/*!
222 Returns the expiry date.
223
224 After an active QGeoAreaMonitorInfo has expired the region is no longer monitored
225 and the QGeoAreaMonitorInfo object is removed from the list of
226 \l {QGeoAreaMonitorSource::activeMonitors()}{active monitors}.
227
228 If the expiry \l QDateTime is invalid the QGeoAreaMonitorInfo object is treated as not having
229 an expiry date. This implies an indefinite monitoring period if the object is persistent or
230 until the current application closes if the object is non-persistent.
231
232 \sa QGeoAreaMonitorSource::activeMonitors()
233 */
234QDateTime QGeoAreaMonitorInfo::expiration() const
235{
236 return d->expiry;
237}
238
239/*!
240 Sets the expiry date and time to \a expiry.
241 */
242void QGeoAreaMonitorInfo::setExpiration(const QDateTime &expiry)
243{
244 d.detach();
245 d->expiry = expiry;
246}
247
248/*!
249 Returns true if the QGeoAreaMonitorInfo is persistent.
250 The default value for this property is false.
251
252 A non-persistent QGeoAreaMonitorInfo will be removed by the system once
253 the application owning the monitor object stops. Persistent objects remain
254 active and can be retrieved once the application restarts.
255
256 If the system triggers an event associated to a persistent QGeoAreaMonitorInfo
257 the relevant application will be re-started and the appropriate signal emitted.
258
259 \sa setPersistent()
260 */
261bool QGeoAreaMonitorInfo::isPersistent() const
262{
263 return d->persistent;
264}
265
266/*!
267 Sets the QGeoAreaMonitorInfo object's persistence to \a isPersistent.
268
269 Note that setting this flag does not imply that \l QGeoAreaMonitorSource
270 supports persistent monitoring.
271 \l QGeoAreaMonitorSource::supportedAreaMonitorFeatures() can be used to
272 check for this feature's availability.
273
274 \sa isPersistent()
275 */
276void QGeoAreaMonitorInfo::setPersistent(bool isPersistent)
277{
278 d.detach();
279 d->persistent = isPersistent;
280}
281
282
283/*!
284 Returns the set of platform specific parameters used by this
285 QGeoAreaMonitorInfo.
286
287 \sa setNotificationParameters()
288 */
289QVariantMap QGeoAreaMonitorInfo::notificationParameters() const
290{
291 return d->notificationParameters;
292}
293
294/*!
295 Sets the set of platform specific \a parameters used by QGeoAreaMonitorInfo.
296
297 \sa notificationParameters()
298 */
299void QGeoAreaMonitorInfo::setNotificationParameters(const QVariantMap &parameters)
300{
301 d.detach();
302 d->notificationParameters = parameters;
303}
304
305/*!
306 \internal
307*/
308void QGeoAreaMonitorInfo::detach()
309{
310 if (d)
311 d.detach();
312 else
313 d = new QGeoAreaMonitorInfoPrivate;
314}
315
316bool QGeoAreaMonitorInfo::equals(const QGeoAreaMonitorInfo &lhs, const QGeoAreaMonitorInfo &rhs)
317{
318 return (lhs.d->name == rhs.d->name &&
319 lhs.d->uid == rhs.d->uid &&
320 lhs.d->shape == rhs.d->shape &&
321 lhs.d->persistent == rhs.d->persistent &&
322 lhs.d->expiry == rhs.d->expiry &&
323 lhs.d->notificationParameters == rhs.d->notificationParameters);
324}
325
326#ifndef QT_NO_DATASTREAM
327
328/*!
329 \fn QDataStream &QGeoAreaMonitorInfo::operator<<(QDataStream &stream, const QGeoAreaMonitorInfo &monitor)
330
331 Writes the given \a monitor to the specified \a stream.
332
333 \sa {Serializing Qt Data Types}
334*/
335QDataStream &QGeoAreaMonitorInfo::dataStreamOut(QDataStream &ds, const QGeoAreaMonitorInfo &monitor)
336{
337 ds << monitor.name() << monitor.d->uid << monitor.area()
338 << monitor.isPersistent() << monitor.notificationParameters() << monitor.expiration();
339 return ds;
340}
341
342/*!
343 \fn QDataStream &QGeoAreaMonitorInfo::operator>>(QDataStream &stream, QGeoAreaMonitorInfo &monitor)
344
345 Reads a area monitoring data from the specified \a stream into the given
346 \a monitor.
347
348 \sa {Serializing Qt Data Types}
349*/
350QDataStream &QGeoAreaMonitorInfo::dataStreamIn(QDataStream &ds, QGeoAreaMonitorInfo &monitor)
351{
352 QString s;
353 ds >> s;
354 monitor = QGeoAreaMonitorInfo(s);
355
356 QUuid id;
357 ds >> id;
358 monitor.d->uid = id;
359
360 QGeoShape shape;
361 ds >> shape;
362 monitor.setArea(shape);
363
364 bool persistent;
365 ds >> persistent;
366 monitor.setPersistent(persistent);
367
368 QVariantMap map;
369 ds >> map;
370 monitor.setNotificationParameters(map);
371
372 QDateTime dt;
373 ds >> dt;
374 monitor.setExpiration(dt);
375
376 return ds;
377}
378
379#endif
380
381#ifndef QT_NO_DEBUG_STREAM
382QDebug QGeoAreaMonitorInfo::debugStreaming(QDebug dbg, const QGeoAreaMonitorInfo &monitor)
383{
384 QDebugStateSaver saver(dbg);
385 dbg.nospace() << "QGeoAreaMonitorInfo(\"" << qPrintable(monitor.name())
386 << "\", " << monitor.area()
387 << ", persistent: " << monitor.isPersistent()
388 << ", expiry: " << monitor.expiration() << ")";
389 return dbg;
390}
391
392#endif
393
394size_t qHash(const QGeoAreaMonitorInfo &key, size_t seed) noexcept
395{
396 return qHashMulti(seed, key.d->uid);
397}
398
399namespace QTest
400{
401
402char *toString(const QGeoAreaMonitorInfo &info)
403{
404 QString result;
405 QDebug dbg(&result);
406 dbg << info;
407 return qstrdup(qPrintable(result));
408}
409
410} // namespace QTest
411
412QT_END_NAMESPACE
QGeoAreaMonitorInfoPrivate(const QGeoAreaMonitorInfoPrivate &other)
char * toString(const MyPoint &point)
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:191