File indexing completed on 2024-05-12 05:22:32
0001 /* 0002 SPDX-FileCopyrightText: 2012 Jan Grulich <grulja@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #pragma once 0008 0009 #include "kgapimaps_export.h" 0010 #include "staticmapmarker.h" 0011 #include "staticmappath.h" 0012 0013 #include <QSize> 0014 #include <QUrl> 0015 0016 #include <KContacts/Address> 0017 #include <KContacts/Geo> 0018 0019 namespace KGAPI2 0020 { 0021 0022 /** 0023 * @brief A class to build a URL from StaticMapMarkers and StaticMapPaths to 0024 * fetch a map tile. 0025 * 0026 * @author Jan Grulich <grulja@gmail.com> 0027 * @since 0.4 0028 */ 0029 class KGAPIMAPS_EXPORT StaticMapUrl 0030 { 0031 public: 0032 enum LocationType { Undefined = -1, String, KABCAddress, KABCGeo }; 0033 0034 enum ImageFormat { PNG, PNG32, GIF, JPG, JPGBaseline }; 0035 0036 enum MapType { Roadmap, Satellite, Terrain, Hybrid }; 0037 0038 enum Scale { Normal = 1, TwiceBigger = 2 }; 0039 0040 /** 0041 * @brief Constructs an empty StaticMapUrl 0042 */ 0043 explicit StaticMapUrl(); 0044 0045 /** 0046 * @brief Constructs a new StaticMapUrl 0047 * 0048 * @param location Location of map center in QString 0049 * @param size Requested size of the map image 0050 * @param zoom Zoom level of map 0051 * @param sensor Sensor specifies whether the application requesting the 0052 * static map is using a sensor to determine the user's location. 0053 */ 0054 StaticMapUrl(const QString &location, const QSize &size, quint32 zoom, bool sensor); 0055 0056 /** 0057 * @brief Constructs a new StaticMapUrl 0058 * 0059 * @param address Location of map center in KContacts::Address 0060 * @param size Requested size of the map image 0061 * @param zoom Zoom level of map 0062 * @param sensor Sensor specifies whether the application requesting the 0063 * static map is using a sensor to determine the user's location. 0064 */ 0065 StaticMapUrl(const KContacts::Address &address, const QSize &size, quint32 zoom, bool sensor); 0066 0067 /** 0068 * @brief Constructs a new StaticMapUrl 0069 * 0070 * @param geo Location of map center in KContacts::Geo 0071 * @param size Requested size of the map image 0072 * @param zoom Zoom level of map 0073 * @param sensor Sensor specifies whether the application requesting the static map is 0074 * using a sensor to determine the user's location. 0075 */ 0076 StaticMapUrl(const KContacts::Geo &geo, const QSize &size, quint32 zoom, bool sensor); 0077 0078 /** 0079 * @brief Copy constructor 0080 */ 0081 StaticMapUrl(const StaticMapUrl &other); 0082 0083 /** 0084 * @brief Destructor 0085 */ 0086 virtual ~StaticMapUrl(); 0087 0088 /** 0089 * @brief Returns in which format the location is stored. 0090 */ 0091 [[nodiscard]] LocationType locationType() const; 0092 0093 /** 0094 * @brief Returns map image format 0095 */ 0096 [[nodiscard]] ImageFormat format() const; 0097 0098 /** 0099 * @brief Sets map image format (default is PNG) 0100 * 0101 * @param format 0102 */ 0103 void setFormat(const ImageFormat format); 0104 0105 /** 0106 * @brief Returns whether map url is valid 0107 */ 0108 bool isValid() const; 0109 0110 /** 0111 * @brief Returns map center in QString 0112 * 0113 * Returns empty QString if location is not defined in QString 0114 */ 0115 [[nodiscard]] QString locationString() const; 0116 0117 /** 0118 * @brief Defines center of the map 0119 * 0120 * @param location Location (required when no markers are present) of 0121 * center of the map in QString 0122 */ 0123 void setLocation(const QString &location); 0124 0125 /** 0126 * @brief Returns map center in KContacts::Address 0127 * 0128 * Returns empty KContacts::Address if location is not defined in KContacts::Address 0129 */ 0130 [[nodiscard]] KContacts::Address locationAddress() const; 0131 0132 /** 0133 * @brief Defines center of the map 0134 * 0135 * @param address Location (required when no markers are present) of center 0136 * of the map in KContacts::Address 0137 */ 0138 void setLocation(const KContacts::Address &address); 0139 0140 /** 0141 * @brief Returns map center in KContacts::Geo 0142 * 0143 * Returns invalid KContacts::Geo if location is not defined in KContacts::Geo 0144 */ 0145 [[nodiscard]] KContacts::Geo locationGeo() const; 0146 0147 /** 0148 * @brief Defines center of the map 0149 * 0150 * @param geo Location (required when no markers are present) of center 0151 * of the map in KContacts::Geo 0152 */ 0153 void setLocation(const KContacts::Geo &geo); 0154 0155 /** 0156 * @brief Returns type of map 0157 */ 0158 [[nodiscard]] MapType mapType() const; 0159 0160 /** 0161 * @brief Sets type of map (roadmap by default) 0162 * 0163 * @param type 0164 */ 0165 void setMapType(const MapType type); 0166 0167 /** 0168 * @brief Returns list of markers 0169 * 0170 * Returns empty QList if no marker were added 0171 */ 0172 [[nodiscard]] QList<StaticMapMarker> markers() const; 0173 0174 /** 0175 * @brief Adds marker to map 0176 * 0177 * @param marker 0178 */ 0179 void setMarker(const StaticMapMarker &marker); 0180 0181 /** 0182 * @brief Adds markers to map 0183 * 0184 * @param markers 0185 */ 0186 void setMarkers(const QList<StaticMapMarker> &markers); 0187 0188 /** 0189 * @brief Returns list paths 0190 * 0191 * Returns empty QList if no path were added 0192 */ 0193 [[nodiscard]] QList<StaticMapPath> paths() const; 0194 0195 /** 0196 * @brief Adds path to map 0197 * 0198 * @param path 0199 */ 0200 void setPath(const StaticMapPath &path); 0201 0202 /** 0203 * @brief Adds paths to map 0204 * 0205 * @param paths 0206 */ 0207 void setPaths(const QList<StaticMapPath> &paths); 0208 0209 /** 0210 * @brief Returns size of map tile 0211 */ 0212 [[nodiscard]] QSize size() const; 0213 0214 /** 0215 * @brief Sets size of requested map tile. 0216 * 0217 * @param size Maximum size is 640x640 0218 */ 0219 void setSize(const QSize &size); 0220 0221 /** 0222 * @brief Returns scale of map 0223 */ 0224 [[nodiscard]] Scale scale() const; 0225 0226 /** 0227 * @brief Sets scale of map (default is 1) 0228 * 0229 * @param scale 0230 */ 0231 void setScale(const Scale scale); 0232 0233 /** 0234 * @brief Returns whether the application uses a sensor to determine user's 0235 * location. 0236 */ 0237 [[nodiscard]] bool sensorUsed() const; 0238 0239 /** 0240 * @brief Sets whether the application uses a sensor to determine the user's 0241 * location. 0242 * 0243 * @param sensor 0244 */ 0245 void setSensorUsed(const bool sensor); 0246 0247 /** 0248 * @brief Returns visible area in QString 0249 * 0250 * Returns empty QString if visible area is not defined in QString 0251 */ 0252 [[nodiscard]] QString visibleLocationString() const; 0253 0254 /** 0255 * @brief Sets visible location. 0256 * 0257 * You can use this instead of using center and zoom parameters. 0258 * 0259 * Specifies location that should remain visible on the map, though 0260 * no markers or other indicators will be displayed. Use this parameter to 0261 * ensure that certain features or map location are shown on the static map. 0262 * 0263 * @param location 0264 */ 0265 void setVisibleLocation(const QString &location); 0266 0267 /** 0268 * @brief Returns visible area in KContacts::Address 0269 * 0270 * Returns empty KContacts::Address if visible area is not defined in KContacts::Address 0271 */ 0272 [[nodiscard]] KContacts::Address visibleLocationAddress() const; 0273 0274 /** 0275 * @brief Sets visible location. 0276 * 0277 * You can use this instead of using center and zoom parameters. 0278 * 0279 * Visible specifies location that should remain visible on the map, though 0280 * no markers or other indicators will be displayed. Use this parameter to 0281 * ensure that certain features or map location are shown on the static map. 0282 * 0283 * @param address 0284 */ 0285 void setVisibleLocation(const KContacts::Address &address); 0286 0287 /** 0288 * @brief Returns visible area in KContacts::Geo 0289 * 0290 * Returns empty KContacts::Geo if visible area is not defined in KContacts::Geo 0291 */ 0292 [[nodiscard]] KContacts::Geo visibleLocationGeo() const; 0293 0294 /** 0295 * @brief Sets visible location. 0296 * 0297 * You can use this instead of using center and zoom parameters. 0298 * 0299 * Visible specifies location that should remain visible on the map, though 0300 * no markers or other indicators will be displayed. Use this parameter to 0301 * ensure that certain features or map location are shown on the static map. 0302 * 0303 * @param geo 0304 */ 0305 void setVisibleLocation(const KContacts::Geo &geo); 0306 0307 /** 0308 * @brief Returns type of visible location 0309 */ 0310 [[nodiscard]] LocationType visibleLocationType() const; 0311 0312 /** 0313 * @brief Returns zoom level of map 0314 * 0315 * Returns -1 if zoom level is not defined 0316 */ 0317 [[nodiscard]] qint8 zoomLevel() const; 0318 0319 /** 0320 * @brief Sets zoom level of the map 0321 * 0322 * @param zoom Zoom parameter can be in range 0 to 21 where 21 is maximum 0323 * zoom level. 0324 */ 0325 void setZoomLevel(const quint32 zoom); 0326 0327 /** 0328 * @brief Returns constructed url from all defined parameters 0329 */ 0330 [[nodiscard]] QUrl url() const; 0331 0332 /** 0333 * @brief Assignment operator 0334 */ 0335 StaticMapUrl &operator=(const StaticMapUrl &other); 0336 0337 private: 0338 class Private; 0339 Private *const d; 0340 friend class Private; 0341 }; 0342 0343 } // namespace KGAPI2