| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: http://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtLocation module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL3$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at http://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPLv3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or later as published by the Free |
| 28 | ** Software Foundation and appearing in the file LICENSE.GPL included in |
| 29 | ** the packaging of this file. Please review the following information to |
| 30 | ** ensure the GNU General Public License version 2.0 requirements will be |
| 31 | ** met: http://www.gnu.org/licenses/gpl-2.0.html. |
| 32 | ** |
| 33 | ** $QT_END_LICENSE$ |
| 34 | ** |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | #ifndef QTILEPROVIDEROSM_H |
| 38 | #define QTILEPROVIDEROSM_H |
| 39 | |
| 40 | #include <QtLocation/private/qgeomaptype_p.h> |
| 41 | #include <QtLocation/private/qgeocameracapabilities_p.h> |
| 42 | #include <QtCore/QUrl> |
| 43 | #include <QtCore/QVector> |
| 44 | #include <QtNetwork/QNetworkAccessManager> |
| 45 | #include <QtNetwork/QNetworkReply> |
| 46 | #include <QtCore/QPointer> |
| 47 | #include <QTimer> |
| 48 | #include <algorithm> |
| 49 | #include <QtCore/QJsonDocument> |
| 50 | #include <QtCore/QJsonObject> |
| 51 | #include <QDateTime> |
| 52 | |
| 53 | QT_BEGIN_NAMESPACE |
| 54 | |
| 55 | class TileProvider: public QObject |
| 56 | { |
| 57 | Q_OBJECT |
| 58 | public: |
| 59 | enum Status {Idle, |
| 60 | Resolving, |
| 61 | Valid, |
| 62 | Invalid }; |
| 63 | |
| 64 | TileProvider(); |
| 65 | // "Online" constructor. Needs resolution to fetch the parameters |
| 66 | TileProvider(const QUrl &urlRedirector, bool highDpi = false); |
| 67 | // Offline constructor. Doesn't need URLRedirector and networkmanager |
| 68 | TileProvider(const QString &urlTemplate, |
| 69 | const QString &format, |
| 70 | const QString ©RightMap, |
| 71 | const QString ©RightData, |
| 72 | bool highDpi = false, |
| 73 | int minimumZoomLevel = 0, |
| 74 | int maximumZoomLevel = 19); |
| 75 | |
| 76 | ~TileProvider(); |
| 77 | void setNetworkManager(QNetworkAccessManager *nm); |
| 78 | |
| 79 | void resolveProvider(); |
| 80 | void handleError(QNetworkReply::NetworkError error); |
| 81 | void setupProvider(); |
| 82 | |
| 83 | inline bool isValid() const; |
| 84 | inline bool isInvalid() const; |
| 85 | inline bool isResolved() const; |
| 86 | inline Status status() const; |
| 87 | |
| 88 | inline QString mapCopyRight() const; |
| 89 | inline QString dataCopyRight() const; |
| 90 | inline QString styleCopyRight() const; |
| 91 | inline QString format() const; |
| 92 | inline int minimumZoomLevel() const; |
| 93 | inline int maximumZoomLevel() const; |
| 94 | inline const QDateTime ×tamp() const; |
| 95 | inline bool isHighDpi() const; |
| 96 | inline bool isHTTPS() const; |
| 97 | QUrl tileAddress(int x, int y, int z) const; |
| 98 | |
| 99 | // Optional properties, not needed to construct a provider |
| 100 | void setStyleCopyRight(const QString ©right); |
| 101 | void setTimestamp(const QDateTime ×tamp); |
| 102 | |
| 103 | Status m_status; |
| 104 | QUrl m_urlRedirector; // The URL from where to fetch the URL template in case of a provider to resolve. |
| 105 | QNetworkAccessManager *m_nm; |
| 106 | QString m_urlTemplate; |
| 107 | QString m_format; |
| 108 | QString m_copyRightMap; |
| 109 | QString m_copyRightData; |
| 110 | QString m_copyRightStyle; |
| 111 | QString m_urlPrefix; |
| 112 | QString m_urlSuffix; |
| 113 | int m_minimumZoomLevel; |
| 114 | int m_maximumZoomLevel; |
| 115 | QDateTime m_timestamp; |
| 116 | bool m_highDpi; |
| 117 | |
| 118 | int paramsLUT[3]; //Lookup table to handle possibly shuffled x,y,z |
| 119 | QString paramsSep[2]; // what goes in between %x, %y and %z |
| 120 | |
| 121 | Q_SIGNALS: |
| 122 | void resolutionFinished(TileProvider *provider); |
| 123 | void resolutionError(TileProvider *provider); |
| 124 | |
| 125 | public Q_SLOTS: |
| 126 | void onNetworkReplyFinished(); |
| 127 | void onNetworkReplyError(QNetworkReply::NetworkError error); |
| 128 | |
| 129 | friend class QGeoTileProviderOsm; |
| 130 | }; |
| 131 | |
| 132 | class QGeoTileProviderOsm: public QObject |
| 133 | { |
| 134 | Q_OBJECT |
| 135 | |
| 136 | friend class QGeoTileFetcherOsm; |
| 137 | friend class QGeoMapReplyOsm; |
| 138 | friend class QGeoTiledMappingManagerEngineOsm; |
| 139 | public: |
| 140 | enum Status {Idle, |
| 141 | Resolving, |
| 142 | Resolved }; |
| 143 | |
| 144 | QGeoTileProviderOsm(QNetworkAccessManager *nm, |
| 145 | const QGeoMapType &mapType, |
| 146 | const QVector<TileProvider *> &providers, |
| 147 | const QGeoCameraCapabilities &cameraCapabilities); |
| 148 | ~QGeoTileProviderOsm(); |
| 149 | |
| 150 | QUrl tileAddress(int x, int y, int z) const; |
| 151 | QString mapCopyRight() const; |
| 152 | QString dataCopyRight() const; |
| 153 | QString styleCopyRight() const; |
| 154 | QString format() const; |
| 155 | int minimumZoomLevel() const; |
| 156 | int maximumZoomLevel() const; |
| 157 | bool isHighDpi() const; |
| 158 | const QGeoMapType &mapType() const; |
| 159 | bool isValid() const; |
| 160 | bool isResolved() const; |
| 161 | const QDateTime timestamp() const; |
| 162 | QGeoCameraCapabilities cameraCapabilities() const; |
| 163 | |
| 164 | Q_SIGNALS: |
| 165 | void resolutionFinished(const QGeoTileProviderOsm *provider); |
| 166 | void resolutionError(const QGeoTileProviderOsm *provider); |
| 167 | void resolutionRequired(); |
| 168 | |
| 169 | public Q_SLOTS: |
| 170 | void resolveProvider(); |
| 171 | void disableRedirection(); |
| 172 | |
| 173 | protected Q_SLOTS: |
| 174 | void onResolutionFinished(TileProvider *provider); |
| 175 | void onResolutionError(TileProvider *provider); |
| 176 | void updateCameraCapabilities(); |
| 177 | |
| 178 | protected: |
| 179 | void addProvider(TileProvider *provider); |
| 180 | |
| 181 | /* Data members */ |
| 182 | |
| 183 | QNetworkAccessManager *m_nm; |
| 184 | QVector<TileProvider *> m_providerList; |
| 185 | TileProvider *m_provider; |
| 186 | int m_providerId; |
| 187 | QGeoMapType m_mapType; |
| 188 | Status m_status; |
| 189 | QGeoCameraCapabilities m_cameraCapabilities; |
| 190 | }; |
| 191 | |
| 192 | QT_END_NAMESPACE |
| 193 | |
| 194 | #endif // QTILEPROVIDEROSM_H |
| 195 | |