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