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
qdeclarativepolygonmapitem_p_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 Paolo Angelelli <paolo.angelelli@gmail.com>
2// Copyright (C) 2022 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4// Qt-Security score:significant reason:default
5
6#ifndef QDECLARATIVEPOLYGONMAPITEM_P_P_H
7#define QDECLARATIVEPOLYGONMAPITEM_P_P_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtCore/QList>
21#include <QtCore/QScopedValueRollback>
22#include <QtGui/QMatrix4x4>
23#include <QtGui/QColor>
24
25#include <QSGFlatColorMaterial>
26
27#include <QtLocation/private/qlocationglobal_p.h>
28#include <QtLocation/private/qgeomapitemgeometry_p.h>
29#include <QtLocation/private/qdeclarativepolygonmapitem_p.h>
30#include <QtLocation/private/qdeclarativepolylinemapitem_p_p.h>
31
32#include <QtPositioning/private/qdoublevector2d_p.h>
33
34QT_BEGIN_NAMESPACE
35
36class QQuickShape;
37class QQuickShapePath;
38
39class Q_LOCATION_EXPORT QGeoMapPolygonGeometry : public QGeoMapItemGeometry
40{
41public:
42 enum MapBorderBehaviour {
43 DrawOnce,
44 Duplicate,
45 WrapAround
46 };
47
48 QGeoMapPolygonGeometry();
49
50 inline void setAssumeSimple(bool value) { assumeSimple_ = value; }
51
52 void updateSourcePoints(const QGeoMap &map,
53 const QList<QList<QDoubleVector2D>> &path,
54 MapBorderBehaviour wrapping = Duplicate);
55
56 QPainterPath srcPath() const { return srcPath_; }
57 qreal maxCoord() const { return maxCoord_; }
58
59protected:
60 QPainterPath srcPath_;
61 qreal maxCoord_ = 0.0;
62 bool assumeSimple_ = false;
63};
64
65class Q_LOCATION_EXPORT QDeclarativePolygonMapItemPrivate
66{
67 Q_DISABLE_COPY_MOVE(QDeclarativePolygonMapItemPrivate)
68public:
69 QDeclarativePolygonMapItemPrivate(QDeclarativePolygonMapItem &polygon)
70 : m_poly(polygon)
71 {
72 }
73
74 virtual ~QDeclarativePolygonMapItemPrivate();
75 virtual void onLinePropertiesChanged() = 0;
76 virtual void markSourceDirtyAndUpdate() = 0;
77 virtual void onMapSet() = 0;
78 virtual void onGeoGeometryChanged() = 0;
79 virtual void onGeoGeometryUpdated() = 0;
80 virtual void onItemGeometryChanged() = 0;
81 virtual void updatePolish() = 0;
82 virtual void afterViewportChanged() = 0;
83 virtual QSGNode * updateMapItemPaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) = 0;
84 virtual bool contains(const QPointF &point) const = 0;
85
87};
88
89class Q_LOCATION_EXPORT QDeclarativePolygonMapItemPrivateCPU: public QDeclarativePolygonMapItemPrivate
90{
91public:
92 QDeclarativePolygonMapItemPrivateCPU(QDeclarativePolygonMapItem &polygon);
93 ~QDeclarativePolygonMapItemPrivateCPU() override;
94
95 void onLinePropertiesChanged() override
96 {
97 // mark dirty just in case we're a width change
98 markSourceDirtyAndUpdate();
99 }
100 void markSourceDirtyAndUpdate() override
101 {
102 m_geometry.markSourceDirty();
103 m_poly.polishAndUpdate();
104 }
105 void regenerateCache()
106 {
107 if (!m_poly.map() || m_poly.map()->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator)
108 return;
109 const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_poly.map()->geoProjection());
110 m_geopathProjected.clear();
111 m_geopathProjected << QList<QDoubleVector2D>();
112 QList<QDoubleVector2D> &pP = m_geopathProjected.last();
113 if (m_poly.referenceSurface() == QLocation::ReferenceSurface::Globe) {
114 const QList<QGeoCoordinate> realPath = QDeclarativeGeoMapItemUtils::greaterCirclePath(m_poly.m_geopoly.perimeter(),
115 QDeclarativeGeoMapItemUtils::ClosedPath);
116 pP.reserve(realPath.size());
117 for (const QGeoCoordinate &c : realPath)
118 pP << p.geoToMapProjection(c);
119 } else {
120 pP.reserve(m_poly.m_geopoly.perimeter().size());
121 const QList<QGeoCoordinate> perimeter = m_poly.m_geopoly.perimeter();
122 for (const QGeoCoordinate &c : perimeter)
123 pP << p.geoToMapProjection(c);
124 }
125 for (int i = 0; i < m_poly.m_geopoly.holesCount(); i++) {
126 m_geopathProjected << QList<QDoubleVector2D>();
127 QList<QDoubleVector2D> &pH = m_geopathProjected.last();
128 if (m_poly.referenceSurface() == QLocation::ReferenceSurface::Globe) {
129 const QList<QGeoCoordinate> realPath = QDeclarativeGeoMapItemUtils::greaterCirclePath(m_poly.m_geopoly.holePath(i),
130 QDeclarativeGeoMapItemUtils::ClosedPath);
131 pH.reserve(realPath.size());
132 for (const QGeoCoordinate &c : realPath)
133 pH << p.geoToMapProjection(c);
134 } else {
135 pH.reserve(m_poly.m_geopoly.holePath(i).size());
136 const QList<QGeoCoordinate> holePath = m_poly.m_geopoly.holePath(i);
137 for (const QGeoCoordinate &c : holePath)
138 pH << p.geoToMapProjection(c);
139 }
140 }
141 }
142 void updateCache()
143 {
144 if (!m_poly.map() || m_poly.map()->geoProjection().projectionType() != QGeoProjection::ProjectionWebMercator)
145 return;
146 const QGeoProjectionWebMercator &p = static_cast<const QGeoProjectionWebMercator&>(m_poly.map()->geoProjection());
147 QList<QDoubleVector2D> &pP = m_geopathProjected.first();
148 if (m_poly.referenceSurface() == QLocation::ReferenceSurface::Globe && m_poly.m_geopoly.perimeter().size() > 1) {
149 regenerateCache(); //giving up here. Too difficult to take back all the interpolated points
150 } else {
151 pP << p.geoToMapProjection(m_poly.m_geopoly.perimeter().last());
152 }
153 }
154 void afterViewportChanged() override
155 {
156 markSourceDirtyAndUpdate();
157 }
158 void onMapSet() override
159 {
160 regenerateCache();
161 markSourceDirtyAndUpdate();
162 }
163 void onGeoGeometryChanged() override
164 {
165 regenerateCache();
166 markSourceDirtyAndUpdate();
167 }
168 void onGeoGeometryUpdated() override
169 {
170 updateCache();
171 markSourceDirtyAndUpdate();
172 }
173 void onItemGeometryChanged() override
174 {
175 onGeoGeometryChanged();
176 }
177 void updatePolish() override;
178 QSGNode *updateMapItemPaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data) override;
179 bool contains(const QPointF &point) const override;
180
181 QList<QList<QDoubleVector2D>> m_geopathProjected;
182 QGeoMapPolygonGeometry m_geometry;
183 QQuickShape *m_shape = nullptr;
184 QQuickShapePath *m_shapePath = nullptr;
185 QDeclarativeGeoMapPainterPath *m_painterPath = nullptr;
186};
187
188QT_END_NAMESPACE
189
190#endif // QDECLARATIVEPOLYGONMAPITEM_P_P_H
virtual void afterViewportChanged()=0
virtual QSGNode * updateMapItemPaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *data)=0
virtual void onItemGeometryChanged()=0
virtual void onGeoGeometryChanged()=0
virtual bool contains(const QPointF &point) const =0
virtual void onLinePropertiesChanged()=0
virtual void markSourceDirtyAndUpdate()=0
virtual void onGeoGeometryUpdated()=0
Combined button and popup list for selecting options.