Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qgeopositioninfo.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#include "qgeopositioninfo.h"
4#include "private/qgeopositioninfo_p.h"
5#include <QHash>
6#include <QDebug>
7#include <QDataStream>
8#include <QtCore/QtNumeric>
9
10#include <algorithm>
11
13
15
16
65
71{
73 d->coord = coordinate;
74}
75
83
98
105
107
108
113 if (this == &other)
114 return *this;
115
116 d = other.d;
117 return *this;
118}
119
151{
152 return d->timestamp.isValid() && d->coord.isValid();
153}
154
163{
164 d.detach();
165 d->timestamp = timestamp;
166}
167
176{
177 return d->timestamp;
178}
179
186{
187 d.detach();
188 d->coord = coordinate;
189}
190
199{
200 return d->coord;
201}
202
213
230
239
248
253{
254 if (d)
255 d.detach();
256 else
258}
259
260bool QGeoPositionInfo::equals(const QGeoPositionInfo &lhs, const QGeoPositionInfo &rhs)
261{
262 return *lhs.d == *rhs.d;
263}
264
265#ifndef QT_NO_DEBUG_STREAM
266QDebug QGeoPositionInfo::debugStreaming(QDebug dbg, const QGeoPositionInfo &info)
267{
268 QDebugStateSaver saver(dbg);
269 dbg.nospace() << "QGeoPositionInfo(" << info.d->timestamp;
270 dbg.nospace() << ", "; // timestamp force dbg.space() -> reverting here
271 dbg << info.d->coord;
272
273 QList<QGeoPositionInfo::Attribute> attribs = info.d->doubleAttribs.keys();
274 std::stable_sort(attribs.begin(), attribs.end()); // Output a sorted list from an unsorted hash.
275 for (int i = 0; i < attribs.size(); ++i) {
276 dbg << ", ";
277 switch (attribs[i]) {
279 dbg << "Direction=";
280 break;
282 dbg << "GroundSpeed=";
283 break;
285 dbg << "VerticalSpeed=";
286 break;
288 dbg << "MagneticVariation=";
289 break;
291 dbg << "HorizontalAccuracy=";
292 break;
294 dbg << "VerticalAccuracy=";
295 break;
297 dbg << "DirectionAccuracy=";
298 break;
299 }
300 dbg << info.d->doubleAttribs[attribs[i]];
301 }
302 dbg << ')';
303 return dbg;
304}
305#endif
306
307
308#ifndef QT_NO_DATASTREAM
316QDataStream &QGeoPositionInfo::dataStreamOut(QDataStream &stream, QGeoPositionInfo::Attribute attr)
317{
318 return stream << qint32(attr);
319}
320
328QDataStream &QGeoPositionInfo::dataStreamIn(QDataStream &stream, QGeoPositionInfo::Attribute &attr)
329{
330 qint32 a;
331 stream >> a;
332 attr = static_cast<QGeoPositionInfo::Attribute>(a);
333 return stream;
334}
335
344QDataStream &QGeoPositionInfo::dataStreamOut(QDataStream &stream, const QGeoPositionInfo &info)
345{
346 stream << info.d->timestamp;
347 stream << info.d->coord;
348 stream << info.d->doubleAttribs;
349 return stream;
350}
351
361QDataStream &QGeoPositionInfo::dataStreamIn(QDataStream &stream, QGeoPositionInfo &info)
362{
363 stream >> info.d->timestamp;
364 stream >> info.d->coord;
365 stream >> info.d->doubleAttribs;
366 return stream;
367}
368#endif
369
373
376 timestamp(other.timestamp),
378 doubleAttribs(other.doubleAttribs)
379{
380}
381
386
388{
389 return timestamp == other.timestamp
390 && coord == other.coord
391 && doubleAttribs == other.doubleAttribs;
392}
393
398
399size_t qHash(const QGeoPositionInfo &key, size_t seed) noexcept
400{
401 return qHashMulti(seed, key.d->coord);
402}
403
404namespace QTest
405{
406
408{
410 QDebug dbg(&result);
411 dbg << info;
412
413 return qstrdup(qPrintable(result));
414}
415
416} // namespace QTest
417
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore\reentrant
Definition qdatetime.h:283
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
\inmodule QtCore
\inmodule QtCore
void detach()
If the shared data object's reference count is greater than 1, this function creates a deep copy of t...
\inmodule QtPositioning
bool isValid
This property holds the validity of this geo coordinate.
static QGeoPositionInfoPrivate * get(const QGeoPositionInfo &info)
QHash< QGeoPositionInfo::Attribute, qreal > doubleAttribs
bool operator==(const QGeoPositionInfoPrivate &other) const
\inmodule QtPositioning
bool isValid() const
Returns true if the timestamp() and coordinate() values are both valid.
Attribute
Defines the attributes for positional information.
qreal attribute(Attribute attribute) const
Returns the value of the specified attribute as a qreal value.
~QGeoPositionInfo()
Destroys a QGeoPositionInfo object.
void setCoordinate(const QGeoCoordinate &coordinate)
Sets the coordinate for this position to coordinate.
QGeoCoordinate coordinate() const
Returns the coordinate for this position.
void setAttribute(Attribute attribute, qreal value)
Sets the value for attribute to value.
QGeoPositionInfo()
Creates an invalid QGeoPositionInfo object.
void setTimestamp(const QDateTime &timestamp)
Sets the date and time at which this position was reported to timestamp.
QDateTime timestamp() const
Returns the date and time at which this position was reported, in UTC time.
friend class QGeoPositionInfoPrivate
bool hasAttribute(Attribute attribute) const
Returns true if the specified attribute is present for this QGeoPositionInfo object.
void removeAttribute(Attribute attribute)
Removes the specified attribute and its value.
bool remove(const Key &key)
Removes the item that has the key from the hash.
Definition qhash.h:958
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
Definition qhash.h:1007
\inmodule QtCore
Definition qshareddata.h:19
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
char * toString(const MyPoint &point)
Q_CORE_EXPORT char * qstrdup(const char *)
EGLStreamKHR stream
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
EGLOutputLayerEXT EGLint attribute
size_t qHash(const QGeoPositionInfo &key, size_t seed) noexcept
constexpr QtPrivate::QHashMultiReturnType< T... > qHashMulti(size_t seed, const T &... args) noexcept(std::conjunction_v< QtPrivate::QNothrowHashable< T >... >)
#define QT_IMPL_METATYPE_EXTERN(TYPE)
Definition qmetatype.h:1390
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qQNaN()
GLuint64 key
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint coord
GLuint64EXT * result
[6]
const GLint * attribs
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define QT_DEFINE_QESDP_SPECIALIZATION_DTOR(Class)
#define qPrintable(string)
Definition qstring.h:1531
int qint32
Definition qtypes.h:49
double qreal
Definition qtypes.h:187
QSharedPointer< T > other(t)
[5]
QHostInfo info
[0]