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
qgeoshape.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 "qgeoshape.h"
5#include "qgeoshape_p.h"
6#include "qgeorectangle.h"
7#include "qgeocircle.h"
8#include "qgeopath.h"
9#include "qgeopolygon.h"
10
11
12#ifndef QT_NO_DEBUG_STREAM
13#include <QtCore/QDebug>
14#endif
15
16#ifndef QT_NO_DATASTREAM
17#include <QtCore/QDataStream>
18#endif
19
21
23
28
32
34{
35 return type == other.type;
36}
37
105inline QGeoShapePrivate *QGeoShape::d_func()
106{
107 return static_cast<QGeoShapePrivate *>(d_ptr.data());
108}
109
110inline const QGeoShapePrivate *QGeoShape::d_func() const
111{
112 return static_cast<const QGeoShapePrivate *>(d_ptr.constData());
113}
114
121
126: d_ptr(other.d_ptr)
127{
128}
129
134: d_ptr(d)
135{
136}
137
138bool QGeoShape::equals(const QGeoShape &lhs, const QGeoShape &rhs)
139{
140 if (lhs.d_func() == rhs.d_func())
141 return true;
142
143 if (!lhs.d_func() || !rhs.d_func())
144 return false;
145
146 return *lhs.d_func() == *rhs.d_func();
147}
148
155
160{
161 Q_D(const QGeoShape);
162
163 if (d)
164 return d->type;
165 else
166 return UnknownType;
167}
168
174{
175 Q_D(const QGeoShape);
176
177 if (d)
178 return d->isValid();
179 else
180 return false;
181}
182
189{
190 Q_D(const QGeoShape);
191
192 if (d)
193 return d->isEmpty();
194 else
195 return true;
196}
197
201bool QGeoShape::contains(const QGeoCoordinate &coordinate) const
202{
203 Q_D(const QGeoShape);
204
205 if (d)
206 return d->contains(coordinate);
207 else
208 return false;
209}
210
218{
219 Q_D(const QGeoShape);
220
221 if (d)
222 return d->boundingGeoRectangle();
223 else
224 return QGeoRectangle();
225}
226
233{
234 Q_D(const QGeoShape);
235
236 if (d)
237 return d->center();
238 else
239 return QGeoCoordinate();
240}
241
260{
261 if (this == &other)
262 return *this;
263
264 d_ptr = other.d_ptr;
265 return *this;
266}
267
274{
275 return QStringLiteral("QGeoShape(%1)").arg(type());
276}
277
278#ifndef QT_NO_DEBUG_STREAM
279QDebug QGeoShape::debugStreaming(QDebug dbg, const QGeoShape &shape)
280{
281 QDebugStateSaver saver(dbg);
282 dbg.nospace() << "QGeoShape(";
283 switch (shape.type()) {
285 dbg << "Unknown";
286 break;
288 dbg << "Rectangle";
289 break;
291 dbg << "Path";
292 break;
294 dbg << "Polygon";
295 break;
297 dbg << "Circle";
298 }
299
300 dbg << ')';
301
302 return dbg;
303}
304#endif
305
306#ifndef QT_NO_DATASTREAM
307QDataStream &QGeoShape::dataStreamOut(QDataStream &stream, const QGeoShape &shape)
308{
309 stream << quint32(shape.type());
310 switch (shape.type()) {
312 break;
314 QGeoRectangle r = shape;
315 stream << r.topLeft() << r.bottomRight();
316 break;
317 }
319 QGeoCircle c = shape;
320 stream << c.center() << c.radius();
321 break;
322 }
323 case QGeoShape::PathType: {
324 QGeoPath p = shape;
325 stream << p.width();
326 stream << p.path().size();
327 for (const auto &c: p.path())
328 stream << c;
329 break;
330 }
332 QGeoPolygon p = shape;
333 stream << p.perimeter().size();
334 for (const auto &c: p.perimeter())
335 stream << c;
336 break;
337 }
338 }
339
340 return stream;
341}
342
343QDataStream &QGeoShape::dataStreamIn(QDataStream &stream, QGeoShape &shape)
344{
346 stream >> type;
347
348 switch (type) {
350 shape = QGeoShape();
351 break;
355 stream >> tl >> br;
356 shape = QGeoRectangle(tl, br);
357 break;
358 }
361 qreal r;
362 stream >> c >> r;
363 shape = QGeoCircle(c, r);
364 break;
365 }
366 case QGeoShape::PathType: {
367 QList<QGeoCoordinate> l;
369 qreal width;
370 stream >> width;
371 qsizetype sz;
372 stream >> sz;
373 for (qsizetype i = 0; i < sz; i++) {
374 stream >> c;
375 l.append(c);
376 }
377 shape = QGeoPath(l, width);
378 break;
379 }
381 QList<QGeoCoordinate> l;
383 qsizetype sz;
384 stream >> sz;
385 for (qsizetype i = 0; i < sz; i++) {
386 stream >> c;
387 l.append(c);
388 }
389 shape = QGeoPolygon(l);
390 break;
391 }
392 }
393
394 return stream;
395}
396#endif
397
404size_t qHash(const QGeoShape &shape, size_t seed) noexcept
405{
406 if (shape.d_ptr)
407 return shape.d_ptr->hash(seed);
408 else
409 return qHashMulti(seed, shape.type());
410}
411
413
414#include "moc_qgeoshape.cpp"
415
\inmodule QtCore\reentrant
Definition qdatastream.h:46
\inmodule QtCore
\inmodule QtCore
\inmodule QtPositioning
Definition qgeocircle.h:15
\inmodule QtPositioning
\inmodule QtPositioning
Definition qgeopath.h:16
\inmodule QtPositioning
Definition qgeopolygon.h:16
\inmodule QtPositioning
virtual bool operator==(const QGeoShapePrivate &other) const
Definition qgeoshape.cpp:33
virtual ~QGeoShapePrivate()
Definition qgeoshape.cpp:29
virtual size_t hash(size_t seed) const =0
\inmodule QtPositioning
Definition qgeoshape.h:17
QGeoShape()
Constructs a new invalid geo shape of \l UnknownType.
bool isValid
This property holds the validity of the geo shape.
Definition qgeoshape.h:20
QGeoShape & operator=(const QGeoShape &other)
Assigns other to this geo shape and returns a reference to this geo shape.
QSharedDataPointer< QGeoShapePrivate > d_ptr
Definition qgeoshape.h:61
ShapeType type
This property holds the type of this geo shape.
Definition qgeoshape.h:19
Q_INVOKABLE QGeoRectangle boundingGeoRectangle() const
Returns a QGeoRectangle representing the geographical bounding rectangle of the geo shape,...
Q_INVOKABLE bool contains(const QGeoCoordinate &coordinate) const
Returns whether the coordinate coordinate is contained within this geo shape.
Q_INVOKABLE QString toString() const
Returns a string representation of this geo shape.
~QGeoShape()
Destroys this geo shape.
ShapeType
Describes the type of the shape.
Definition qgeoshape.h:30
@ UnknownType
Definition qgeoshape.h:31
@ PolygonType
Definition qgeoshape.h:35
@ RectangleType
Definition qgeoshape.h:32
bool isEmpty
This property defines whether this geo shape is empty.
Definition qgeoshape.h:21
QGeoCoordinate center
Definition qgeoshape.h:22
const T * constData() const noexcept
Returns a const pointer to the shared data object.
Definition qshareddata.h:51
T * data()
Returns a pointer to the shared data object.
Definition qshareddata.h:47
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
Combined button and popup list for selecting options.
EGLStreamKHR stream
size_t qHash(const QFileSystemWatcherPathKey &key, size_t seed=0)
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
GLboolean r
[2]
GLint GLsizei width
GLenum type
const GLubyte * c
GLsizei const GLchar *const * path
GLfloat GLfloat p
[1]
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define QStringLiteral(str)
unsigned int quint32
Definition qtypes.h:50
ptrdiff_t qsizetype
Definition qtypes.h:165
double qreal
Definition qtypes.h:187
QSharedPointer< T > other(t)
[5]