QGeoView  1.0
QGeoView documentation
QGVGlobal.h
1 /***************************************************************************
2  * QGeoView is a Qt / C ++ widget for visualizing geographic data.
3  * Copyright (C) 2018-2025 Andrey Yaroshenko.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, see https://www.gnu.org/licenses.
17  ****************************************************************************/
18 
19 #pragma once
20 
21 #include <QDebug>
22 #include <QNetworkAccessManager>
23 #include <QPainterPath>
24 #include <QPointF>
25 #include <QRectF>
26 
27 #ifndef QGV_LIB_DECL
28 #if defined(QGV_EXPORT)
29 #define QGV_LIB_DECL Q_DECL_EXPORT
30 #else
31 #define QGV_LIB_DECL Q_DECL_IMPORT
32 #endif
33 #endif
34 
35 namespace QGV {
36 
37 enum class Projection
38 {
39  EPSG3857,
40 };
41 
42 enum class TilesType
43 {
44  Satellite,
45  Schema,
46  Hybrid,
47 };
48 
49 enum BDGExLayer
50 {
51  ctm25,
52  ctm50,
53  ctm100,
54  ctm250,
55  ctmmultiescalas,
56  ctmmultiescalas_mercator
57 };
58 
59 enum class MapState
60 {
61  Idle,
62  Animation,
63  Wheel,
64  MovingMap,
65  MovingObjects,
66  SelectionRect,
67 };
68 
69 enum class DistanceUnits
70 {
71  Meters,
72  Kilometers,
73  NauticalMiles,
74  Miles,
75 };
76 
77 enum class MouseAction : int
78 {
79  Move = 0x1,
80  ZoomWheel = 0x2,
81  ZoomRect = 0x4,
82  Selection = 0x8,
83  Tooltip = 0x10,
84  ContextMenu = 0x20,
85  MoveObjects = 0x40,
86  All = 0xFF,
87 };
88 Q_DECLARE_FLAGS(MouseActions, MouseAction)
89 
90 enum class ItemFlag : int
91 {
92  IgnoreScale = 0x1,
93  IgnoreAzimuth = 0x2,
94  Highlightable = 0x4,
95  Highlighted = 0x8,
96  HighlightCustom = 0x10,
97  SelectCustom = 0x20,
98  Transformed = 0x40,
99  Clickable = 0x80,
100  Movable = 0x100,
101 };
102 Q_DECLARE_FLAGS(ItemFlags, ItemFlag)
103 
104 class QGV_LIB_DECL GeoPos
105 {
106 public:
107  GeoPos();
108  GeoPos(double lat, double lon);
109 
110  bool isEmpty() const;
111 
112  double latitude() const;
113  double longitude() const;
114 
115  void setLat(double late);
116  void setLon(double lon);
117 
118  QString lonToString(const QString& format = "[+-]d") const;
119  QString latToString(const QString& format = "[+-]d") const;
120 
121  static QString lonToString(double lon, const QString& format = "[+-]d");
122  static QString latToString(double lat, const QString& format = "[+-]d");
123 
124  bool operator==(const GeoPos& rhs);
125  bool operator!=(const GeoPos& rhs);
126 
127 private:
128  bool mEmpty;
129  double mLat;
130  double mLon;
131 };
132 
133 class QGV_LIB_DECL GeoRect
134 {
135 public:
136  GeoRect();
137  GeoRect(double lat1, double lon1, double lat2, double lon2);
138  GeoRect(GeoPos const& pos1, GeoPos const& pos2);
139 
140  bool isEmpty() const;
141 
142  GeoPos topLeft() const;
143  GeoPos topRight() const;
144  GeoPos bottomLeft() const;
145  GeoPos bottomRight() const;
146  double lonLeft() const;
147  double lonRight() const;
148  double latBottom() const;
149  double latTop() const;
150 
151  bool contains(GeoPos const& pos) const;
152  bool contains(GeoRect const& rect) const;
153  bool intersects(GeoRect const& rect) const;
154 
155  bool operator==(const GeoRect& rhs);
156  bool operator!=(const GeoRect& rhs);
157 
158 private:
159  GeoPos mTopLeft;
160  GeoPos mBottomRight;
161 };
162 
163 class QGV_LIB_DECL GeoTilePos
164 {
165 public:
166  GeoTilePos();
167  GeoTilePos(int zoom, const QPoint& pos);
168  GeoTilePos(const GeoTilePos& other);
169  GeoTilePos(const GeoTilePos&& other);
170  GeoTilePos& operator=(const GeoTilePos& other);
171  GeoTilePos& operator=(const GeoTilePos&& other);
172 
173  bool operator<(const GeoTilePos& other) const;
174 
175  int zoom() const;
176  QPoint pos() const;
177 
178  bool contains(const GeoTilePos& other) const;
179  GeoTilePos parent(int parentZoom) const;
180 
181  GeoRect toGeoRect() const;
182  QString toQuadKey() const;
183 
184  static GeoTilePos geoToTilePos(int zoom, const GeoPos& geoPos);
185 
186 private:
187  int mZoom;
188  QPoint mPos;
189 };
190 
191 QGV_LIB_DECL void setNetworkManager(QNetworkAccessManager* manager);
192 QGV_LIB_DECL QNetworkAccessManager* getNetworkManager();
193 
194 QGV_LIB_DECL QTransform createTransfrom(QPointF const& projAnchor, double scale, double azimuth);
195 QGV_LIB_DECL QTransform createTransfromScale(QPointF const& projAnchor, double scale);
196 QGV_LIB_DECL QTransform createTransfromAzimuth(QPointF const& projAnchor, double azimuth);
197 QGV_LIB_DECL QPainterPath createTextPath(const QRect& rect, const QString& text, const QFont& font, int penWidth);
198 
199 QGV_LIB_DECL void setDrawDebug(bool enabled);
200 QGV_LIB_DECL bool isDrawDebug();
201 QGV_LIB_DECL void setPrintDebug(bool enabled);
202 QGV_LIB_DECL bool isPrintDebug();
203 
204 } // namespace QGV
205 
206 QGV_LIB_DECL QDebug operator<<(QDebug debug, const QGV::GeoPos& value);
207 QGV_LIB_DECL QDebug operator<<(QDebug debug, const QGV::GeoRect& value);
208 QGV_LIB_DECL QDebug operator<<(QDebug debug, const QGV::GeoTilePos& value);
209 
210 Q_DECLARE_METATYPE(QGV::GeoPos)
211 Q_DECLARE_METATYPE(QGV::GeoRect)
212 Q_DECLARE_METATYPE(QGV::GeoTilePos)
213 
214 Q_DECLARE_OPERATORS_FOR_FLAGS(QGV::ItemFlags)
215 
216 #define qgvDebug \
217  if (QGV::isPrintDebug()) \
218  qDebug
219 #define qgvInfo \
220  if (QGV::isPrintDebug()) \
221  qInfo
222 #define qgvWarning \
223  if (QGV::isPrintDebug()) \
224  qWarning
225 #define qgvCritical qCritical
Definition: QGVGlobal.h:105
Definition: QGVGlobal.h:134
Definition: QGVGlobal.h:164