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
qgeopath_p.h
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#ifndef QGEOPATH_P_H
5#define QGEOPATH_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtPositioning/private/qpositioningglobal_p.h>
19#include "qgeoshape_p.h"
20#include "qgeocoordinate.h"
22#include <QtPositioning/qgeopath.h>
23#include <QtCore/QList>
24
26
27inline static void computeBBox(const QList<QGeoCoordinate> &m_path, QList<double> &m_deltaXs,
28 double &m_minX, double &m_maxX, double &m_minLati, double &m_maxLati,
29 QGeoRectangle &m_bbox)
30{
31 if (m_path.isEmpty()) {
32 m_deltaXs.clear();
33 m_minX = qInf();
34 m_maxX = -qInf();
35 m_minLati = qInf();
36 m_maxLati = -qInf();
37 m_bbox = QGeoRectangle();
38 return;
39 }
40
41 m_minLati = m_maxLati = m_path.at(0).latitude();
42 qsizetype minId = 0;
43 qsizetype maxId = 0;
44 m_deltaXs.resize(m_path.size());
45 m_deltaXs[0] = m_minX = m_maxX = 0.0;
46
47 for (qsizetype i = 1; i < m_path.size(); i++) {
48 const QGeoCoordinate &geoFrom = m_path.at(i-1);
49 const QGeoCoordinate &geoTo = m_path.at(i);
50 double longiFrom = geoFrom.longitude();
51 double longiTo = geoTo.longitude();
52 double deltaLongi = longiTo - longiFrom;
53 if (qAbs(deltaLongi) > 180.0) {
54 if (longiTo > 0.0)
55 longiTo -= 360.0;
56 else
57 longiTo += 360.0;
58 deltaLongi = longiTo - longiFrom;
59 }
60 m_deltaXs[i] = m_deltaXs[i-1] + deltaLongi;
61 if (m_deltaXs[i] < m_minX) {
62 m_minX = m_deltaXs[i];
63 minId = i;
64 }
65 if (m_deltaXs[i] > m_maxX) {
66 m_maxX = m_deltaXs[i];
67 maxId = i;
68 }
69 if (geoTo.latitude() > m_maxLati)
70 m_maxLati = geoTo.latitude();
71 if (geoTo.latitude() < m_minLati)
72 m_minLati = geoTo.latitude();
73 }
74
75 m_bbox = QGeoRectangle(QGeoCoordinate(m_maxLati, m_path.at(minId).longitude()),
76 QGeoCoordinate(m_minLati, m_path.at(maxId).longitude()));
77}
78
79inline static void updateBBox(const QList<QGeoCoordinate> &m_path, QList<double> &m_deltaXs,
80 double &m_minX, double &m_maxX, double &m_minLati, double &m_maxLati,
81 QGeoRectangle &m_bbox)
82{
83 if (m_path.isEmpty()) {
84 m_deltaXs.clear();
85 m_minX = qInf();
86 m_maxX = -qInf();
87 m_minLati = qInf();
88 m_maxLati = -qInf();
89 m_bbox = QGeoRectangle();
90 return;
91 } else if (m_path.size() == 1) { // was 0 now is 1
92 m_deltaXs.resize(1);
93 m_deltaXs[0] = m_minX = m_maxX = 0.0;
94 m_minLati = m_maxLati = m_path.at(0).latitude();
95 m_bbox = QGeoRectangle(QGeoCoordinate(m_maxLati, m_path.at(0).longitude()),
96 QGeoCoordinate(m_minLati, m_path.at(0).longitude()));
97 return;
98 } else if ( m_path.size() != m_deltaXs.size() + 1 ) { // this case should not happen
99 computeBBox(m_path, m_deltaXs, m_minX, m_maxX, m_minLati, m_maxLati, m_bbox); // something went wrong
100 return;
101 }
102
103 const QGeoCoordinate &geoFrom = m_path.at(m_path.size()-2);
104 const QGeoCoordinate &geoTo = m_path.last();
105 double longiFrom = geoFrom.longitude();
106 double longiTo = geoTo.longitude();
107 double deltaLongi = longiTo - longiFrom;
108 if (qAbs(deltaLongi) > 180.0) {
109 if (longiTo > 0.0)
110 longiTo -= 360.0;
111 else
112 longiTo += 360.0;
113 deltaLongi = longiTo - longiFrom;
114 }
115
116 m_deltaXs.push_back(m_deltaXs.last() + deltaLongi);
117 double currentMinLongi = m_bbox.topLeft().longitude();
118 double currentMaxLongi = m_bbox.bottomRight().longitude();
119 if (m_deltaXs.last() < m_minX) {
120 m_minX = m_deltaXs.last();
121 currentMinLongi = geoTo.longitude();
122 }
123 if (m_deltaXs.last() > m_maxX) {
124 m_maxX = m_deltaXs.last();
125 currentMaxLongi = geoTo.longitude();
126 }
127 if (geoTo.latitude() > m_maxLati)
128 m_maxLati = geoTo.latitude();
129 if (geoTo.latitude() < m_minLati)
130 m_minLati = geoTo.latitude();
131 m_bbox = QGeoRectangle(QGeoCoordinate(m_maxLati, currentMinLongi),
132 QGeoCoordinate(m_minLati, currentMaxLongi));
133}
134
135// Lazy by default. Eager, within the module, used only in MapItems/MapObjectsQSG
136class Q_POSITIONING_EXPORT QGeoPathPrivate : public QGeoShapePrivate
137{
138public:
139 QGeoPathPrivate();
140 QGeoPathPrivate(const QList<QGeoCoordinate> &path, const qreal width = 0.0);
141 ~QGeoPathPrivate();
142
143// QGeoShape API
144 virtual QGeoShapePrivate *clone() const override;
145 virtual bool isValid() const override;
146 virtual bool isEmpty() const override;
147 virtual QGeoCoordinate center() const override;
148 virtual bool operator==(const QGeoShapePrivate &other) const override;
149 virtual bool contains(const QGeoCoordinate &coordinate) const override;
150 virtual QGeoRectangle boundingGeoRectangle() const override;
151 size_t hash(size_t seed) const override;
152
153// QGeoPathPrivate API
154 virtual const QList<QGeoCoordinate> &path() const;
155 virtual bool lineContains(const QGeoCoordinate &coordinate) const;
156 virtual qreal width() const;
157 virtual double length(qsizetype indexFrom, qsizetype indexTo) const;
158 virtual qsizetype size() const;
159 virtual QGeoCoordinate coordinateAt(qsizetype index) const;
160 virtual bool containsCoordinate(const QGeoCoordinate &coordinate) const;
161
162 virtual void setWidth(const qreal &width);
163 virtual void translate(double degreesLatitude, double degreesLongitude);
164 virtual void setPath(const QList<QGeoCoordinate> &path);
165 virtual void clearPath();
166 virtual void addCoordinate(const QGeoCoordinate &coordinate);
167 virtual void insertCoordinate(qsizetype index, const QGeoCoordinate &coordinate);
168 virtual void replaceCoordinate(qsizetype index, const QGeoCoordinate &coordinate);
169 virtual void removeCoordinate(const QGeoCoordinate &coordinate);
170 virtual void removeCoordinate(qsizetype index);
171 virtual void computeBoundingBox();
172 virtual void markDirty();
173
174// data members
175 QList<QGeoCoordinate> m_path;
176 qreal m_width = 0;
177 QGeoRectangle m_bbox; // cached
178 double m_leftBoundWrapped; // cached
179 bool m_bboxDirty = false;
180};
181
182class Q_POSITIONING_EXPORT QGeoPathPrivateEager : public QGeoPathPrivate
183{
184public:
185 QGeoPathPrivateEager();
186 QGeoPathPrivateEager(const QList<QGeoCoordinate> &path, const qreal width = 0.0);
187 ~QGeoPathPrivateEager();
188
189// QGeoShapePrivate API
190 virtual QGeoShapePrivate *clone() const override;
191 virtual void translate(double degreesLatitude, double degreesLongitude) override;
192
193// QGeoShapePrivate API
194 virtual void markDirty() override;
195 virtual void addCoordinate(const QGeoCoordinate &coordinate) override;
196 virtual void computeBoundingBox() override;
197
198// *Eager API
199 void updateBoundingBox();
200
201// data members
202 QList<double> m_deltaXs; // longitude deltas from m_path[0]
203 double m_minX = 0; // minimum value inside deltaXs
204 double m_maxX = 0; // maximum value inside deltaXs
205 double m_minLati = 0; // minimum latitude. paths do not wrap around through the poles
206 double m_maxLati = 0; // minimum latitude. paths do not wrap around through the poles
207};
208
209// This is a mean of creating a QGeoPathPrivateEager and injecting it into QGeoPaths via operator=
210class Q_POSITIONING_EXPORT QGeoPathEager : public QGeoPath
211{
212 Q_GADGET
213public:
214
215 QGeoPathEager();
216 QGeoPathEager(const QList<QGeoCoordinate> &path, const qreal &width = 0.0);
217 QGeoPathEager(const QGeoPath &other);
218 QGeoPathEager(const QGeoShape &other);
219 ~QGeoPathEager();
220};
221
222QT_END_NAMESPACE
223
224#endif // QGEOPATH_P_H
Combined button and popup list for selecting options.
static void updateBBox(const QList< QGeoCoordinate > &m_path, QList< double > &m_deltaXs, double &m_minX, double &m_maxX, double &m_minLati, double &m_maxLati, QGeoRectangle &m_bbox)
Definition qgeopath_p.h:79
static QT_BEGIN_NAMESPACE void computeBBox(const QList< QGeoCoordinate > &m_path, QList< double > &m_deltaXs, double &m_minX, double &m_maxX, double &m_minLati, double &m_maxLati, QGeoRectangle &m_bbox)
Definition qgeopath_p.h:27