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.cpp
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
5#include <QtQml/QQmlInfo>
6#include <QtQml/QQmlEngine>
7#include <QLocale>
8
9QT_BEGIN_NAMESPACE
10
11/*!
12 \qmltype Plugin
13 //! \nativetype QDeclarativeGeoServiceProvider
14 \inqmlmodule QtLocation
15 \ingroup qml-QtLocation5-common
16 \since QtLocation 5.5
17
18 \brief The Plugin type describes a Location based services plugin.
19
20 The Plugin type is used to declaratively specify which available
21 GeoServices plugin should be used for various tasks in the Location API.
22 Plugins are used by \l Map, \l RouteModel, and \l GeocodeModel
23 types, as well as a variety of others.
24
25 Plugins recognized by the system have a \l name property, a simple string
26 normally indicating the name of the service that the Plugin retrieves
27 data from. They also have a variety of features, which can be test for using the
28 \l {supportsRouting()}, \l {supportsGeocoding()}, \l {supportsMapping()},
29 \l {supportsPlaces()} and \l {supportsNavigation()} methods.
30
31 When a Plugin object is created, it is "detached" and not associated with
32 any actual service plugin. Once it has received information via setting
33 its \l name, \l preferred, or \l required properties, it will choose an
34 appropriate service plugin to attach to. Plugin objects can only be
35 attached once; to use multiple plugins, create multiple Plugin objects.
36
37 \section2 Example Usage
38
39 The following snippet shows a Plugin object being created with the
40 \l required and \l preferred properties set. This Plugin will attach to the
41 first found plugin that supports both mapping and geocoding, and will
42 prefer plugins named "here" or "osm" to any others.
43
44 \code
45 Plugin {
46 id: plugin
47 preferred: ["here", "osm"]
48 required: Plugin.AnyMappingFeatures | Plugin.AnyGeocodingFeatures
49 }
50 \endcode
51*/
52
53QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent)
54: QObject(parent), required_(new QDeclarativeGeoServiceProviderRequirements)
55{
56 locales_.append(QLocale().name());
57}
58
59QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider()
60{
61}
62
63
64
65/*!
66 \qmlproperty string Plugin::name
67
68 This property holds the name of the plugin. Setting this property
69 will cause the Plugin to only attach to a plugin with exactly this
70 name. The value of \l required will be ignored.
71*/
72void QDeclarativeGeoServiceProvider::setName(const QString &name)
73{
74 if (name_ == name)
75 return;
76
77 name_ = name;
78
79 if (complete_)
80 tryAttach();
81
82 emit nameChanged(name_);
83}
84
85/*!
86 \internal
87*/
88bool QDeclarativeGeoServiceProvider::parametersReady() {
89 for (const QDeclarativePluginParameter *p: std::as_const(parameters_)) {
90 if (!p->isInitialized())
91 return false;
92 }
93 return true;
94}
95
96/*!
97 \internal
98*/
99void QDeclarativeGeoServiceProvider::tryAttach()
100{
101 if (!parametersReady())
102 return;
103
104 sharedProvider_.reset();
105
106 if (name_.isEmpty())
107 return;
108
109 sharedProvider_.reset(new QGeoServiceProvider(name_, parameterMap()));
110 sharedProvider_->setQmlEngine(qmlEngine(this));
111 sharedProvider_->setLocale(QLocale(locales_.at(0)));
112 sharedProvider_->setAllowExperimental(experimental_);
113
114 emit attached();
115}
116
117QString QDeclarativeGeoServiceProvider::name() const
118{
119 return name_;
120}
121
122
123/*!
124 \qmlproperty stringlist Plugin::availableServiceProviders
125
126 This property holds a list of all available service plugins' names. This
127 can be used to manually enumerate the available plugins if the
128 control provided by \l name and \l required is not sufficient for your
129 needs.
130*/
131QStringList QDeclarativeGeoServiceProvider::availableServiceProviders()
132{
133 return QGeoServiceProvider::availableServiceProviders();
134}
135
136/*!
137 \internal
138*/
139void QDeclarativeGeoServiceProvider::componentComplete()
140{
141 complete_ = true;
142
143 for (QDeclarativePluginParameter *p: std::as_const(parameters_)) {
144 if (!p->isInitialized()) {
145 connect(p, &QDeclarativePluginParameter::initialized,
146 this, &QDeclarativeGeoServiceProvider::tryAttach);
147 }
148 }
149
150 if (!name_.isEmpty()) {
151 tryAttach();
152 } else if (!prefer_.isEmpty()
153 || required_->mappingRequirements() != NoMappingFeatures
154 || required_->routingRequirements() != NoRoutingFeatures
155 || required_->geocodingRequirements() != NoGeocodingFeatures
156 || required_->placesRequirements() != NoPlacesFeatures
157 || required_->navigationRequirements() != NoNavigationFeatures) {
158
159 QStringList providers = QGeoServiceProvider::availableServiceProviders();
160
161 /* first check any preferred plugins */
162 for (const QString &name : std::as_const(prefer_)) {
163 if (providers.contains(name)) {
164 // so we don't try it again later
165 providers.removeAll(name);
166
167 QGeoServiceProvider sp(name, parameterMap(), experimental_);
168 if (required_->matches(&sp)) {
169 setName(name);
170 return;
171 }
172 }
173 }
174
175 /* then try the rest */
176 for (const QString &name : std::as_const(providers)) {
177 QGeoServiceProvider sp(name, parameterMap(), experimental_);
178 if (required_->matches(&sp)) {
179 setName(name);
180 return;
181 }
182 }
183
184 qmlWarning(this) << "Could not find a plugin with the required features to attach to";
185 }
186}
187
188/*!
189 \qmlmethod bool Plugin::supportsGeocoding(GeocodingFeatures features)
190
191 This method returns a boolean indicating whether the specified set of \a features are supported
192 by the geo service provider plugin. \c True is returned if all specified \a features are
193 supported; otherwise \c false is returned.
194
195 The \a features parameter can be any flag combination of:
196 \table
197 \header
198 \li Feature
199 \li Description
200 \row
201 \li Plugin.NoGeocodingFeatures
202 \li No geocoding features are supported.
203 \row
204 \li Plugin.OnlineGeocodingFeature
205 \li Online geocoding is supported.
206 \row
207 \li Plugin.OfflineGeocodingFeature
208 \li Offline geocoding is supported.
209 \row
210 \li Plugin.ReverseGeocodingFeature
211 \li Reverse geocoding is supported.
212 \row
213 \li Plugin.LocalizedGeocodingFeature
214 \li Supports returning geocoding results with localized addresses.
215 \row
216 \li Plugin.AnyGeocodingFeatures
217 \li Matches a geo service provider that provides any geocoding features.
218 \endtable
219*/
220bool QDeclarativeGeoServiceProvider::supportsGeocoding(const GeocodingFeatures &feature) const
221{
222 QGeoServiceProvider *sp = sharedGeoServiceProvider();
223 QGeoServiceProvider::GeocodingFeatures f =
224 static_cast<QGeoServiceProvider::GeocodingFeature>(int(feature));
225 if (f == QGeoServiceProvider::AnyGeocodingFeatures)
226 return (sp && (sp->geocodingFeatures() != QGeoServiceProvider::NoGeocodingFeatures));
227 else
228 return (sp && (sp->geocodingFeatures() & f) == f);
229}
230
231/*!
232 \qmlmethod bool Plugin::supportsMapping(MappingFeatures features)
233
234 This method returns a boolean indicating whether the specified set of \a features are supported
235 by the geo service provider plugin. True is returned if all specified \a features are
236 supported; otherwise false is returned.
237
238 The \a features parameter can be any flag combination of:
239 \table
240 \header
241 \li Feature
242 \li Description
243 \row
244 \li Plugin.NoMappingFeatures
245 \li No mapping features are supported.
246 \row
247 \li Plugin.OnlineMappingFeature
248 \li Online mapping is supported.
249 \row
250 \li Plugin.OfflineMappingFeature
251 \li Offline mapping is supported.
252 \row
253 \li Plugin.LocalizedMappingFeature
254 \li Supports returning localized map data.
255 \row
256 \li Plugin.AnyMappingFeatures
257 \li Matches a geo service provider that provides any mapping features.
258 \endtable
259*/
260bool QDeclarativeGeoServiceProvider::supportsMapping(const MappingFeatures &feature) const
261{
262 QGeoServiceProvider *sp = sharedGeoServiceProvider();
263 QGeoServiceProvider::MappingFeatures f =
264 static_cast<QGeoServiceProvider::MappingFeature>(int(feature));
265 if (f == QGeoServiceProvider::AnyMappingFeatures)
266 return (sp && (sp->mappingFeatures() != QGeoServiceProvider::NoMappingFeatures));
267 else
268 return (sp && (sp->mappingFeatures() & f) == f);
269}
270
271/*!
272 \qmlmethod bool Plugin::supportsRouting(RoutingFeatures features)
273
274 This method returns a boolean indicating whether the specified set of \a features are supported
275 by the geo service provider plugin. True is returned if all specified \a features are
276 supported; otherwise false is returned.
277
278 The \a features parameter can be any flag combination of:
279 \table
280 \header
281 \li Feature
282 \li Description
283 \row
284 \li Plugin.NoRoutingFeatures
285 \li No routing features are supported.
286 \row
287 \li Plugin.OnlineRoutingFeature
288 \li Online routing is supported.
289 \row
290 \li Plugin.OfflineRoutingFeature
291 \li Offline routing is supported.
292 \row
293 \li Plugin.LocalizedRoutingFeature
294 \li Supports returning routes with localized addresses and instructions.
295 \row
296 \li Plugin.RouteUpdatesFeature
297 \li Updating an existing route based on the current position is supported.
298 \row
299 \li Plugin.AlternativeRoutesFeature
300 \li Supports returning alternative routes.
301 \row
302 \li Plugin.ExcludeAreasRoutingFeature
303 \li Supports specifying a areas which the returned route must not cross.
304 \row
305 \li Plugin.AnyRoutingFeatures
306 \li Matches a geo service provider that provides any routing features.
307 \endtable
308*/
309bool QDeclarativeGeoServiceProvider::supportsRouting(const RoutingFeatures &feature) const
310{
311 QGeoServiceProvider *sp = sharedGeoServiceProvider();
312 QGeoServiceProvider::RoutingFeatures f =
313 static_cast<QGeoServiceProvider::RoutingFeature>(int(feature));
314 if (f == QGeoServiceProvider::AnyRoutingFeatures)
315 return (sp && (sp->routingFeatures() != QGeoServiceProvider::NoRoutingFeatures));
316 else
317 return (sp && (sp->routingFeatures() & f) == f);
318}
319
320/*!
321 \qmlmethod bool Plugin::supportsPlaces(PlacesFeatures features)
322
323 This method returns a boolean indicating whether the specified set of \a features are supported
324 by the geo service provider plugin. True is returned if all specified \a features are
325 supported; otherwise false is returned.
326
327 The \a features parameter can be any flag combination of:
328 \table
329 \header
330 \li Feature
331 \li Description
332 \row
333 \li Plugin.NoPlacesFeatures
334 \li No places features are supported.
335 \row
336 \li Plugin.OnlinePlacesFeature
337 \li Online places is supported.
338 \row
339 \li Plugin.OfflinePlacesFeature
340 \li Offline places is supported.
341 \row
342 \li Plugin.SavePlaceFeature
343 \li Saving categories is supported.
344 \row
345 \li Plugin.RemovePlaceFeature
346 \li Removing or deleting places is supported.
347 \row
348 \li Plugin.PlaceRecommendationsFeature
349 \li Searching for recommended places similar to another place is supported.
350 \row
351 \li Plugin.SearchSuggestionsFeature
352 \li Search suggestions is supported.
353 \row
354 \li Plugin.LocalizedPlacesFeature
355 \li Supports returning localized place data.
356 \row
357 \li Plugin.NotificationsFeature
358 \li Notifications of place and category changes is supported.
359 \row
360 \li Plugin.PlaceMatchingFeature
361 \li Supports matching places from two different geo service providers.
362 \row
363 \li Plugin.AnyPlacesFeatures
364 \li Matches a geo service provider that provides any places features.
365 \endtable
366*/
367bool QDeclarativeGeoServiceProvider::supportsPlaces(const PlacesFeatures &feature) const
368{
369 QGeoServiceProvider *sp = sharedGeoServiceProvider();
370 QGeoServiceProvider::PlacesFeatures f =
371 static_cast<QGeoServiceProvider::PlacesFeature>(int(feature));
372 if (f == QGeoServiceProvider::AnyPlacesFeatures)
373 return (sp && (sp->placesFeatures() != QGeoServiceProvider::NoPlacesFeatures));
374 else
375 return (sp && (sp->placesFeatures() & f) == f);
376}
377
378/*!
379 \qmlmethod bool Plugin::supportsNavigation(NavigationFeatures features)
380
381 This method returns a boolean indicating whether the specified set of \a features are supported
382 by the geo service provider plugin. True is returned if all specified \a features are
383 supported; otherwise false is returned.
384
385 The \a features parameter can be any flag combination of:
386 \table
387 \header
388 \li Feature
389 \li Description
390 \row
391 \li Plugin.NoNavigationFeatures
392 \li No navigation features are supported.
393 \row
394 \li Plugin.OnlineNavigationFeature
395 \li Online navigation is supported.
396 \row
397 \li Plugin.OfflineNavigationFeature
398 \li Offline navigation is supported.
399 \row
400 \li Plugin.AnyNavigationFeatures
401 \li Matches a geo service provider that provides any navigation features.
402 \endtable
403*/
404bool QDeclarativeGeoServiceProvider::supportsNavigation(const QDeclarativeGeoServiceProvider::NavigationFeature &feature) const
405{
406 QGeoServiceProvider *sp = sharedGeoServiceProvider();
407 QGeoServiceProvider::NavigationFeatures f =
408 static_cast<QGeoServiceProvider::NavigationFeature>(int(feature));
409 if (f == QGeoServiceProvider::AnyNavigationFeatures)
410 return (sp && (sp->navigationFeatures() != QGeoServiceProvider::NoNavigationFeatures));
411 else
412 return (sp && (sp->navigationFeatures() & f) == f);
413}
414
415/*!
416 \qmlproperty enumeration Plugin::required
417
418 This property contains the set of features that will be required by the
419 Plugin object when choosing which service plugin to attach to. If the
420 \l name property is set, this has no effect.
421
422 Any of the following values or a bitwise combination of multiple values
423 may be set:
424
425 \list
426 \li Plugin.NoFeatures
427 \li Plugin.GeocodingFeature
428 \li Plugin.ReverseGeocodingFeature
429 \li Plugin.RoutingFeature
430 \li Plugin.MappingFeature
431 \li Plugin.AnyPlacesFeature
432 \endlist
433*/
434QDeclarativeGeoServiceProviderRequirements *QDeclarativeGeoServiceProvider::requirements() const
435{
436 return required_.get();
437}
438
439void QDeclarativeGeoServiceProvider::setRequirements(QDeclarativeGeoServiceProviderRequirements *req)
440{
441 if (!name().isEmpty() || !req)
442 return;
443
444 if (required_ && *required_ == *req)
445 return;
446
447 required_.reset(req);
448 QQmlEngine::setObjectOwnership(req, QQmlEngine::CppOwnership); // To prevent the engine from making this object disappear
449}
450
451/*!
452 \qmlproperty stringlist Plugin::preferred
453
454 This property contains an ordered list of preferred plugin names, which
455 will be checked for the required features set in \l{Plugin::required}{required}
456 before any other available plugins are checked.
457*/
458QStringList QDeclarativeGeoServiceProvider::preferred() const
459{
460 return prefer_;
461}
462
463void QDeclarativeGeoServiceProvider::setPreferred(const QStringList &val)
464{
465 prefer_ = val;
466 emit preferredChanged(prefer_);
467}
468
469/*!
470 \qmlproperty bool Plugin::isAttached
471
472 This property indicates if the Plugin item is attached to a geoservice provider plugin.
473*/
474bool QDeclarativeGeoServiceProvider::isAttached() const
475{
476 return (sharedProvider_ != 0);
477}
478
479/*!
480 \qmlproperty bool Plugin::allowExperimental
481
482 This property indicates if experimental plugins can be used.
483*/
484bool QDeclarativeGeoServiceProvider::allowExperimental() const
485{
486 return experimental_;
487}
488
489void QDeclarativeGeoServiceProvider::setAllowExperimental(bool allow)
490{
491 if (experimental_ == allow)
492 return;
493
494 experimental_ = allow;
495 if (sharedProvider_)
496 sharedProvider_->setAllowExperimental(allow);
497
498 emit allowExperimentalChanged(allow);
499}
500
501/*!
502 \internal
503*/
504QGeoServiceProvider *QDeclarativeGeoServiceProvider::sharedGeoServiceProvider() const
505{
506 return sharedProvider_.get();
507}
508
509/*!
510 \qmlproperty stringlist Plugin::locales
511
512 This property contains an ordered list of preferred plugin locales. If the first locale cannot be accommodated, then
513 the backend falls back to using the second, and so on. By default the locales property contains the system locale.
514
515 The locales are specified as strings which have the format
516 "language[_script][_country]" or "C", where:
517
518 \list
519 \li language is a lowercase, two-letter, ISO 639 language code,
520 \li script is a titlecase, four-letter, ISO 15924 script code,
521 \li country is an uppercase, two- or three-letter, ISO 3166 country code (also "419" as defined by United Nations),
522 \li the "C" locale is identical in behavior to English/UnitedStates as per QLocale
523 \endlist
524
525 If the first specified locale cannot be accommodated, the \l {Plugin} falls back to the next and so forth.
526 Some \l {Plugin} backends may not support a set of locales which are rigidly defined. An arbitrary
527 example is that some \l {Place}'s in France could have French and English localizations, while
528 certain areas in America may only have the English localization available. In the above scenario,
529 the set of supported locales is context dependent on the search location.
530
531 If the \l {Plugin} cannot accommodate any of the preferred locales, the manager falls
532 back to using a supported language that is backend specific.
533
534 For \l {Plugin}'s that do not support locales, the locales list is always empty.
535
536 The following code demonstrates how to set a single and multiple locales:
537 \snippet declarative/plugin.qml Plugin locale
538*/
539QStringList QDeclarativeGeoServiceProvider::locales() const
540{
541 return locales_;
542}
543
544void QDeclarativeGeoServiceProvider::setLocales(const QStringList &locales)
545{
546 if (locales_ == locales)
547 return;
548
549 locales_ = locales;
550
551 if (locales_.isEmpty())
552 locales_.append(QLocale().name());
553
554 if (sharedProvider_)
555 sharedProvider_->setLocale(QLocale(locales_.at(0)));
556
557 emit localesChanged();
558}
559
560/*!
561 \qmlproperty list<PluginParameter> Plugin::parameters
562 \qmldefault
563
564 This property holds the list of plugin parameters.
565*/
566QQmlListProperty<QDeclarativePluginParameter> QDeclarativeGeoServiceProvider::parameters()
567{
568 return QQmlListProperty<QDeclarativePluginParameter>(this,
569 0,
570 parameter_append,
571 parameter_count,
572 parameter_at,
573 parameter_clear);
574}
575
576/*!
577 \internal
578*/
579void QDeclarativeGeoServiceProvider::parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *parameter)
580{
581 QDeclarativeGeoServiceProvider *p = static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
582 p->parameters_.append(parameter);
583 if (p->sharedProvider_)
584 p->sharedProvider_->setParameters(p->parameterMap());
585}
586
587/*!
588 \internal
589*/
590qsizetype QDeclarativeGeoServiceProvider::parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop)
591{
592 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_.count();
593}
594
595/*!
596 \internal
597*/
598QDeclarativePluginParameter *QDeclarativeGeoServiceProvider::parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, qsizetype index)
599{
600 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_[index];
601}
602
603/*!
604 \internal
605*/
606void QDeclarativeGeoServiceProvider::parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop)
607{
608 QDeclarativeGeoServiceProvider *p = static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
609 p->parameters_.clear();
610 if (p->sharedProvider_)
611 p->sharedProvider_->setParameters(p->parameterMap());
612}
613
614/*!
615 \internal
616*/
617QVariantMap QDeclarativeGeoServiceProvider::parameterMap() const
618{
619 QVariantMap map;
620
621 for (const auto *parameter : parameters_)
622 map.insert(parameter->name(), parameter->value());
623
624 return map;
625}
626
627/*******************************************************************************
628*******************************************************************************/
629
630QDeclarativeGeoServiceProviderRequirements::QDeclarativeGeoServiceProviderRequirements(QObject *parent)
631 : QObject(parent)
632{
633}
634
635QDeclarativeGeoServiceProviderRequirements::~QDeclarativeGeoServiceProviderRequirements()
636{
637}
638
639/*!
640 \internal
641*/
642QDeclarativeGeoServiceProvider::MappingFeatures QDeclarativeGeoServiceProviderRequirements::mappingRequirements() const
643{
644 return mapping_;
645}
646
647/*!
648 \internal
649*/
650void QDeclarativeGeoServiceProviderRequirements::setMappingRequirements(const QDeclarativeGeoServiceProvider::MappingFeatures &features)
651{
652 if (mapping_ == features)
653 return;
654
655 mapping_ = features;
656 emit mappingRequirementsChanged(mapping_);
657 emit requirementsChanged();
658}
659
660/*!
661 \internal
662*/
663QDeclarativeGeoServiceProvider::RoutingFeatures QDeclarativeGeoServiceProviderRequirements::routingRequirements() const
664{
665 return routing_;
666}
667
668/*!
669 \internal
670*/
671void QDeclarativeGeoServiceProviderRequirements::setRoutingRequirements(const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
672{
673 if (routing_ == features)
674 return;
675
676 routing_ = features;
677 emit routingRequirementsChanged(routing_);
678 emit requirementsChanged();
679}
680
681/*!
682 \internal
683*/
684QDeclarativeGeoServiceProvider::GeocodingFeatures QDeclarativeGeoServiceProviderRequirements::geocodingRequirements() const
685{
686 return geocoding_;
687}
688
689/*!
690 \internal
691*/
692void QDeclarativeGeoServiceProviderRequirements::setGeocodingRequirements(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
693{
694 if (geocoding_ == features)
695 return;
696
697 geocoding_ = features;
698 emit geocodingRequirementsChanged(geocoding_);
699 emit requirementsChanged();
700}
701
702/*!
703 \internal
704
705 */
706QDeclarativeGeoServiceProvider::PlacesFeatures QDeclarativeGeoServiceProviderRequirements::placesRequirements() const
707{
708 return places_;
709}
710
711/*!
712 \internal
713*/
714void QDeclarativeGeoServiceProviderRequirements::setPlacesRequirements(const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
715{
716 if (places_ == features)
717 return;
718
719 places_ = features;
720 emit placesRequirementsChanged(places_);
721 emit requirementsChanged();
722}
723
724/*!
725 \internal
726*/
727QDeclarativeGeoServiceProvider::NavigationFeatures QDeclarativeGeoServiceProviderRequirements::navigationRequirements() const
728{
729 return navigation_;
730}
731
732/*!
733 \internal
734*/
735void QDeclarativeGeoServiceProviderRequirements::setNavigationRequirements(const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
736{
737 if (navigation_ == features)
738 return;
739
740 navigation_ = features;
741 emit navigationRequirementsChanged(navigation_);
742 emit requirementsChanged();
743}
744
745/*!
746 \internal
747*/
748bool QDeclarativeGeoServiceProviderRequirements::matches(const QGeoServiceProvider *provider) const
749{
750 QGeoServiceProvider::MappingFeatures mapping =
751 static_cast<QGeoServiceProvider::MappingFeatures>(int(mapping_));
752
753 // extra curlies here to avoid "dangling" else, which could belong to either if
754 // same goes for all the rest of these blocks
755 if (mapping == QGeoServiceProvider::AnyMappingFeatures) {
756 if (provider->mappingFeatures() == QGeoServiceProvider::NoMappingFeatures)
757 return false;
758 } else {
759 if ((provider->mappingFeatures() & mapping) != mapping)
760 return false;
761 }
762
763 QGeoServiceProvider::RoutingFeatures routing =
764 static_cast<QGeoServiceProvider::RoutingFeatures>(int(routing_));
765
766 if (routing == QGeoServiceProvider::AnyRoutingFeatures) {
767 if (provider->routingFeatures() == QGeoServiceProvider::NoRoutingFeatures)
768 return false;
769 } else {
770 if ((provider->routingFeatures() & routing) != routing)
771 return false;
772 }
773
774 QGeoServiceProvider::GeocodingFeatures geocoding =
775 static_cast<QGeoServiceProvider::GeocodingFeatures>(int(geocoding_));
776
777 if (geocoding == QGeoServiceProvider::AnyGeocodingFeatures) {
778 if (provider->geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures)
779 return false;
780 } else {
781 if ((provider->geocodingFeatures() & geocoding) != geocoding)
782 return false;
783 }
784
785 QGeoServiceProvider::PlacesFeatures places =
786 static_cast<QGeoServiceProvider::PlacesFeatures>(int(places_));
787
788 if (places == QGeoServiceProvider::AnyPlacesFeatures) {
789 if (provider->placesFeatures() == QGeoServiceProvider::NoPlacesFeatures)
790 return false;
791 } else {
792 if ((provider->placesFeatures() & places) != places)
793 return false;
794 }
795
796 QGeoServiceProvider::NavigationFeatures navigation =
797 static_cast<QGeoServiceProvider::NavigationFeatures>(int(navigation_));
798
799 if (navigation == QGeoServiceProvider::AnyNavigationFeatures) {
800 if (provider->navigationFeatures() == QGeoServiceProvider::NoNavigationFeatures)
801 return false;
802 } else {
803 if ((provider->navigationFeatures() & navigation) != navigation)
804 return false;
805 }
806
807 return true;
808}
809
810bool QDeclarativeGeoServiceProviderRequirements::operator == (const QDeclarativeGeoServiceProviderRequirements &rhs) const
811{
812 return (mapping_ == rhs.mapping_ && routing_ == rhs.routing_
813 && geocoding_ == rhs.geocoding_ && places_ == rhs.places_
814 && navigation_ == rhs.navigation_);
815}
816
817/*******************************************************************************
818*******************************************************************************/
819
820/*!
821 \qmltype PluginParameter
822 //! \nativetype QDeclarativePluginParameter
823 \inqmlmodule QtLocation
824 \ingroup qml-QtLocation5-common
825 \since QtLocation 5.5
826
827 \brief The PluginParameter type describes a parameter for a plugin.
828
829 The PluginParameter object is used to provide a parameter of some kind
830 to a plugin. Typically these parameters contain details like an application
831 token for access to a service, or a proxy server to use for network access,
832 or the serial port to which a serial GPS receiver is connected.
833
834 To set such a parameter, declare a PluginParameter inside an \l Plugin object
835 and give it \l{name} and \l{value} properties. A list of valid parameter names
836 is available from the
837 \l {Qt Location#Plugin References and Parameters}{plugin reference pages}.
838*/
839
840/*!
841 \qmlproperty string PluginParameter::name
842
843 This property holds the name of the plugin parameter as a single formatted string.
844 This property is a write-once property.
845*/
846
847/*!
848 \qmlproperty QVariant PluginParameter::value
849
850 This property holds the value of the plugin parameter which support different types of values (variant).
851 This property is a write-once property.
852*/
853
854/*******************************************************************************
855 * Implementation now in positioningquick
856*******************************************************************************/
857
858QT_END_NAMESPACE