| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2015 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 QDECLARATIVEQGEOSERVICEPROVIDER_H |
| 38 | #define QDECLARATIVEQGEOSERVICEPROVIDER_H |
| 39 | |
| 40 | // |
| 41 | // W A R N I N G |
| 42 | // ------------- |
| 43 | // |
| 44 | // This file is not part of the Qt API. It exists purely as an |
| 45 | // implementation detail. This header file may change from version to |
| 46 | // version without notice, or even be removed. |
| 47 | // |
| 48 | // We mean it. |
| 49 | // |
| 50 | |
| 51 | #include <QtLocation/private/qlocationglobal_p.h> |
| 52 | |
| 53 | #include <QtCore/QMap> |
| 54 | #include <QtCore/QString> |
| 55 | #include <QtCore/QStringList> |
| 56 | #include <QtCore/QVariant> |
| 57 | #include <QtQml/qqml.h> |
| 58 | #include <QtQml/QQmlParserStatus> |
| 59 | #include <QtQml/QQmlListProperty> |
| 60 | #include <QtLocation/QGeoServiceProvider> |
| 61 | #include <QtPositioningQuick/private/qdeclarativepluginparameter_p.h> |
| 62 | |
| 63 | QT_BEGIN_NAMESPACE |
| 64 | |
| 65 | class QDeclarativeGeoServiceProviderRequirements; |
| 66 | |
| 67 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoServiceProvider : public QObject, public QQmlParserStatus |
| 68 | { |
| 69 | Q_OBJECT |
| 70 | Q_ENUMS(RoutingFeature) |
| 71 | Q_ENUMS(GeocodingFeature) |
| 72 | Q_ENUMS(MappingFeature) |
| 73 | Q_ENUMS(PlacesFeature) |
| 74 | |
| 75 | Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) |
| 76 | Q_PROPERTY(QStringList availableServiceProviders READ availableServiceProviders CONSTANT) |
| 77 | Q_PROPERTY(QQmlListProperty<QDeclarativePluginParameter> parameters READ parameters) |
| 78 | Q_PROPERTY(QDeclarativeGeoServiceProviderRequirements *required READ requirements WRITE setRequirements) |
| 79 | Q_PROPERTY(QStringList locales READ locales WRITE setLocales NOTIFY localesChanged) |
| 80 | Q_PROPERTY(QStringList preferred READ preferred WRITE setPreferred NOTIFY preferredChanged) |
| 81 | Q_PROPERTY(bool allowExperimental READ allowExperimental WRITE setAllowExperimental NOTIFY allowExperimentalChanged) |
| 82 | Q_PROPERTY(bool isAttached READ isAttached NOTIFY attached) |
| 83 | |
| 84 | Q_CLASSINFO("DefaultProperty" , "parameters" ) |
| 85 | Q_INTERFACES(QQmlParserStatus) |
| 86 | |
| 87 | public: |
| 88 | explicit QDeclarativeGeoServiceProvider(QObject *parent = nullptr); |
| 89 | ~QDeclarativeGeoServiceProvider(); |
| 90 | |
| 91 | enum RoutingFeature { |
| 92 | NoRoutingFeatures = QGeoServiceProvider::NoRoutingFeatures, |
| 93 | OnlineRoutingFeature = QGeoServiceProvider::OnlineRoutingFeature, |
| 94 | OfflineRoutingFeature = QGeoServiceProvider::OfflineRoutingFeature, |
| 95 | LocalizedRoutingFeature = QGeoServiceProvider::LocalizedRoutingFeature, |
| 96 | RouteUpdatesFeature = QGeoServiceProvider::RouteUpdatesFeature, |
| 97 | AlternativeRoutesFeature = QGeoServiceProvider::AlternativeRoutesFeature, |
| 98 | ExcludeAreasRoutingFeature = QGeoServiceProvider::ExcludeAreasRoutingFeature, |
| 99 | AnyRoutingFeatures = QGeoServiceProvider::AnyRoutingFeatures |
| 100 | }; |
| 101 | |
| 102 | enum GeocodingFeature { |
| 103 | NoGeocodingFeatures = QGeoServiceProvider::NoGeocodingFeatures, |
| 104 | OnlineGeocodingFeature = QGeoServiceProvider::OnlineGeocodingFeature, |
| 105 | OfflineGeocodingFeature = QGeoServiceProvider::OfflineGeocodingFeature, |
| 106 | ReverseGeocodingFeature = QGeoServiceProvider::ReverseGeocodingFeature, |
| 107 | LocalizedGeocodingFeature = QGeoServiceProvider::LocalizedGeocodingFeature, |
| 108 | AnyGeocodingFeatures = QGeoServiceProvider::AnyGeocodingFeatures |
| 109 | }; |
| 110 | |
| 111 | enum MappingFeature { |
| 112 | NoMappingFeatures = QGeoServiceProvider::NoMappingFeatures, |
| 113 | OnlineMappingFeature = QGeoServiceProvider::OnlineMappingFeature, |
| 114 | OfflineMappingFeature = QGeoServiceProvider::OfflineMappingFeature, |
| 115 | LocalizedMappingFeature = QGeoServiceProvider::LocalizedMappingFeature, |
| 116 | AnyMappingFeatures = QGeoServiceProvider::AnyMappingFeatures |
| 117 | }; |
| 118 | |
| 119 | enum PlacesFeature { |
| 120 | NoPlacesFeatures = QGeoServiceProvider::NoPlacesFeatures, |
| 121 | OnlinePlacesFeature = QGeoServiceProvider::OnlinePlacesFeature, |
| 122 | OfflinePlacesFeature = QGeoServiceProvider::OfflinePlacesFeature, |
| 123 | SavePlaceFeature = QGeoServiceProvider::SavePlaceFeature, |
| 124 | RemovePlaceFeature = QGeoServiceProvider::RemovePlaceFeature, |
| 125 | SaveCategoryFeature = QGeoServiceProvider::SaveCategoryFeature, |
| 126 | RemoveCategoryFeature = QGeoServiceProvider::RemoveCategoryFeature, |
| 127 | PlaceRecommendationsFeature = QGeoServiceProvider::PlaceRecommendationsFeature, |
| 128 | SearchSuggestionsFeature = QGeoServiceProvider::SearchSuggestionsFeature, |
| 129 | LocalizedPlacesFeature = QGeoServiceProvider::LocalizedPlacesFeature, |
| 130 | NotificationsFeature = QGeoServiceProvider::NotificationsFeature, |
| 131 | PlaceMatchingFeature = QGeoServiceProvider::PlaceMatchingFeature, |
| 132 | AnyPlacesFeatures = QGeoServiceProvider::AnyPlacesFeatures |
| 133 | }; |
| 134 | |
| 135 | enum NavigationFeature { |
| 136 | NoNavigationFeatures = QGeoServiceProvider::NoNavigationFeatures, |
| 137 | OnlineNavigationFeature = QGeoServiceProvider::OnlineNavigationFeature, |
| 138 | OfflineNavigationFeature = QGeoServiceProvider::OfflineNavigationFeature, |
| 139 | AnyNavigationFeatures = QGeoServiceProvider::AnyNavigationFeatures |
| 140 | }; |
| 141 | |
| 142 | Q_DECLARE_FLAGS(RoutingFeatures, RoutingFeature) |
| 143 | Q_FLAGS(RoutingFeatures) |
| 144 | |
| 145 | Q_DECLARE_FLAGS(GeocodingFeatures, GeocodingFeature) |
| 146 | Q_FLAGS(GeocodingFeatures) |
| 147 | |
| 148 | Q_DECLARE_FLAGS(MappingFeatures, MappingFeature) |
| 149 | Q_FLAGS(MappingFeatures) |
| 150 | |
| 151 | Q_DECLARE_FLAGS(PlacesFeatures, PlacesFeature) |
| 152 | Q_FLAGS(PlacesFeatures) |
| 153 | |
| 154 | Q_DECLARE_FLAGS(NavigationFeatures, NavigationFeature) |
| 155 | Q_FLAGS(NavigationFeatures) |
| 156 | |
| 157 | // From QQmlParserStatus |
| 158 | virtual void classBegin() {} |
| 159 | virtual void componentComplete(); |
| 160 | |
| 161 | void setName(const QString &name); |
| 162 | QString name() const; |
| 163 | |
| 164 | QQmlListProperty<QDeclarativePluginParameter> parameters(); |
| 165 | QVariantMap parameterMap() const; |
| 166 | |
| 167 | QStringList availableServiceProviders(); |
| 168 | |
| 169 | QDeclarativeGeoServiceProviderRequirements *requirements() const; |
| 170 | void setRequirements(QDeclarativeGeoServiceProviderRequirements *req); |
| 171 | |
| 172 | QStringList preferred() const; |
| 173 | void setPreferred(const QStringList &val); |
| 174 | |
| 175 | QGeoServiceProvider *sharedGeoServiceProvider() const; |
| 176 | |
| 177 | Q_INVOKABLE bool supportsRouting(const RoutingFeatures &feature = AnyRoutingFeatures) const; |
| 178 | Q_INVOKABLE bool supportsGeocoding(const GeocodingFeatures &feature = AnyGeocodingFeatures) const; |
| 179 | Q_INVOKABLE bool supportsMapping(const MappingFeatures &feature = AnyMappingFeatures) const; |
| 180 | Q_INVOKABLE bool supportsPlaces(const PlacesFeatures &feature = AnyPlacesFeatures) const; |
| 181 | Q_REVISION(11) Q_INVOKABLE bool supportsNavigation(const NavigationFeature &feature = AnyNavigationFeatures) const; |
| 182 | |
| 183 | QStringList locales() const; |
| 184 | void setLocales(const QStringList &locales); |
| 185 | |
| 186 | bool isAttached() const; |
| 187 | |
| 188 | void setAllowExperimental(bool allow); |
| 189 | bool allowExperimental() const; |
| 190 | |
| 191 | Q_SIGNALS: |
| 192 | void nameChanged(const QString &name); |
| 193 | void localesChanged(); |
| 194 | void attached(); |
| 195 | void preferredChanged(const QStringList &preferences); |
| 196 | void allowExperimentalChanged(bool allow); |
| 197 | |
| 198 | private: |
| 199 | bool parametersReady(); |
| 200 | void tryAttach(); |
| 201 | static void parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *mapObject); |
| 202 | static int parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop); |
| 203 | static QDeclarativePluginParameter *parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, int index); |
| 204 | static void parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop); |
| 205 | |
| 206 | QGeoServiceProvider *sharedProvider_; |
| 207 | QString name_; |
| 208 | QList<QDeclarativePluginParameter *> parameters_; |
| 209 | QDeclarativeGeoServiceProviderRequirements *required_; |
| 210 | bool complete_; |
| 211 | bool experimental_; |
| 212 | QStringList locales_; |
| 213 | QStringList prefer_; |
| 214 | Q_DISABLE_COPY(QDeclarativeGeoServiceProvider) |
| 215 | }; |
| 216 | |
| 217 | class Q_LOCATION_PRIVATE_EXPORT QDeclarativeGeoServiceProviderRequirements : public QObject |
| 218 | { |
| 219 | Q_OBJECT |
| 220 | Q_PROPERTY(QDeclarativeGeoServiceProvider::MappingFeatures mapping |
| 221 | READ mappingRequirements WRITE setMappingRequirements |
| 222 | NOTIFY mappingRequirementsChanged) |
| 223 | Q_PROPERTY(QDeclarativeGeoServiceProvider::RoutingFeatures routing |
| 224 | READ routingRequirements WRITE setRoutingRequirements |
| 225 | NOTIFY routingRequirementsChanged) |
| 226 | Q_PROPERTY(QDeclarativeGeoServiceProvider::GeocodingFeatures geocoding |
| 227 | READ geocodingRequirements WRITE setGeocodingRequirements |
| 228 | NOTIFY geocodingRequirementsChanged) |
| 229 | Q_PROPERTY(QDeclarativeGeoServiceProvider::PlacesFeatures places |
| 230 | READ placesRequirements WRITE setPlacesRequirements |
| 231 | NOTIFY placesRequirementsChanged) |
| 232 | Q_PROPERTY(QDeclarativeGeoServiceProvider::NavigationFeatures navigation |
| 233 | READ navigationRequirements WRITE setNavigationRequirements |
| 234 | NOTIFY navigationRequirementsChanged) |
| 235 | |
| 236 | public: |
| 237 | explicit QDeclarativeGeoServiceProviderRequirements(QObject *parent = 0); |
| 238 | ~QDeclarativeGeoServiceProviderRequirements(); |
| 239 | |
| 240 | QDeclarativeGeoServiceProvider::MappingFeatures mappingRequirements() const; |
| 241 | void setMappingRequirements(const QDeclarativeGeoServiceProvider::MappingFeatures &features); |
| 242 | |
| 243 | QDeclarativeGeoServiceProvider::RoutingFeatures routingRequirements() const; |
| 244 | void setRoutingRequirements(const QDeclarativeGeoServiceProvider::RoutingFeatures &features); |
| 245 | |
| 246 | QDeclarativeGeoServiceProvider::GeocodingFeatures geocodingRequirements() const; |
| 247 | void setGeocodingRequirements(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features); |
| 248 | |
| 249 | QDeclarativeGeoServiceProvider::PlacesFeatures placesRequirements() const; |
| 250 | void setPlacesRequirements(const QDeclarativeGeoServiceProvider::PlacesFeatures &features); |
| 251 | |
| 252 | QDeclarativeGeoServiceProvider::NavigationFeatures navigationRequirements() const; |
| 253 | void setNavigationRequirements(const QDeclarativeGeoServiceProvider::NavigationFeatures &features); |
| 254 | |
| 255 | Q_INVOKABLE bool matches(const QGeoServiceProvider *provider) const; |
| 256 | |
| 257 | bool operator == (const QDeclarativeGeoServiceProviderRequirements &rhs) const; |
| 258 | |
| 259 | Q_SIGNALS: |
| 260 | void mappingRequirementsChanged(const QDeclarativeGeoServiceProvider::MappingFeatures &features); |
| 261 | void routingRequirementsChanged(const QDeclarativeGeoServiceProvider::RoutingFeatures &features); |
| 262 | void geocodingRequirementsChanged(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features); |
| 263 | void placesRequirementsChanged(const QDeclarativeGeoServiceProvider::PlacesFeatures &features); |
| 264 | void navigationRequirementsChanged(const QDeclarativeGeoServiceProvider::NavigationFeatures &features); |
| 265 | |
| 266 | void requirementsChanged(); |
| 267 | |
| 268 | private: |
| 269 | QDeclarativeGeoServiceProvider::MappingFeatures mapping_; |
| 270 | QDeclarativeGeoServiceProvider::RoutingFeatures routing_; |
| 271 | QDeclarativeGeoServiceProvider::GeocodingFeatures geocoding_; |
| 272 | QDeclarativeGeoServiceProvider::PlacesFeatures places_; |
| 273 | QDeclarativeGeoServiceProvider::NavigationFeatures navigation_; |
| 274 | }; |
| 275 | |
| 276 | QT_END_NAMESPACE |
| 277 | |
| 278 | QML_DECLARE_TYPE(QDeclarativeGeoServiceProviderRequirements) |
| 279 | QML_DECLARE_TYPE(QDeclarativeGeoServiceProvider) |
| 280 | |
| 281 | #endif |
| 282 | |