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