5#include <QtQml/QQmlInfo>
6#include <QtQml/QQmlEngine>
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
53QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent)
54: QObject(parent), required_(
new QDeclarativeGeoServiceProviderRequirements)
56 locales_.append(QLocale().name());
59QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider()
66
67
68
69
70
71
72void QDeclarativeGeoServiceProvider::setName(
const QString &name)
82 emit nameChanged(name_);
86
87
88bool QDeclarativeGeoServiceProvider::parametersReady() {
89 for (
const QDeclarativePluginParameter *p: std::as_const(parameters_)) {
90 if (!p->isInitialized())
97
98
99void QDeclarativeGeoServiceProvider::tryAttach()
101 if (!parametersReady())
104 sharedProvider_.reset();
109 sharedProvider_.reset(
new QGeoServiceProvider(name_, parameterMap()));
110 sharedProvider_->setQmlEngine(qmlEngine(
this));
111 sharedProvider_->setLocale(QLocale(locales_.at(0)));
112 sharedProvider_->setAllowExperimental(experimental_);
117QString QDeclarativeGeoServiceProvider::name()
const
124
125
126
127
128
129
130
131QStringList QDeclarativeGeoServiceProvider::availableServiceProviders()
133 return QGeoServiceProvider::availableServiceProviders();
137
138
139void QDeclarativeGeoServiceProvider::componentComplete()
143 for (QDeclarativePluginParameter *p: std::as_const(parameters_)) {
144 if (!p->isInitialized()) {
145 connect(p, &QDeclarativePluginParameter::initialized,
146 this, &QDeclarativeGeoServiceProvider::tryAttach);
150 if (!name_.isEmpty()) {
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) {
159 QStringList providers = QGeoServiceProvider::availableServiceProviders();
162 for (
const QString &name : std::as_const(prefer_)) {
163 if (providers.contains(name)) {
165 providers.removeAll(name);
167 QGeoServiceProvider sp(name, parameterMap(), experimental_);
168 if (required_->matches(&sp)) {
176 for (
const QString &name : std::as_const(providers)) {
177 QGeoServiceProvider sp(name, parameterMap(), experimental_);
178 if (required_->matches(&sp)) {
184 qmlWarning(
this) <<
"Could not find a plugin with the required features to attach to";
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220bool QDeclarativeGeoServiceProvider::supportsGeocoding(
const GeocodingFeatures &feature)
const
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));
228 return (sp && (sp->geocodingFeatures() & f) == f);
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260bool QDeclarativeGeoServiceProvider::supportsMapping(
const MappingFeatures &feature)
const
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));
268 return (sp && (sp->mappingFeatures() & f) == f);
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309bool QDeclarativeGeoServiceProvider::supportsRouting(
const RoutingFeatures &feature)
const
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));
317 return (sp && (sp->routingFeatures() & f) == f);
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367bool QDeclarativeGeoServiceProvider::supportsPlaces(
const PlacesFeatures &feature)
const
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));
375 return (sp && (sp->placesFeatures() & f) == f);
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404bool QDeclarativeGeoServiceProvider::supportsNavigation(
const QDeclarativeGeoServiceProvider::NavigationFeature &feature)
const
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));
412 return (sp && (sp->navigationFeatures() & f) == f);
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434QDeclarativeGeoServiceProviderRequirements *QDeclarativeGeoServiceProvider::requirements()
const
436 return required_.get();
439void QDeclarativeGeoServiceProvider::setRequirements(QDeclarativeGeoServiceProviderRequirements *req)
441 if (!name().isEmpty() || !req)
444 if (required_ && *required_ == *req)
447 required_.reset(req);
448 QQmlEngine::setObjectOwnership(req, QQmlEngine::CppOwnership);
452
453
454
455
456
457
458QStringList QDeclarativeGeoServiceProvider::preferred()
const
463void QDeclarativeGeoServiceProvider::setPreferred(
const QStringList &val)
466 emit preferredChanged(prefer_);
470
471
472
473
474bool QDeclarativeGeoServiceProvider::isAttached()
const
476 return (sharedProvider_ != 0);
480
481
482
483
484bool QDeclarativeGeoServiceProvider::allowExperimental()
const
486 return experimental_;
489void QDeclarativeGeoServiceProvider::setAllowExperimental(
bool allow)
491 if (experimental_ == allow)
494 experimental_ = allow;
496 sharedProvider_->setAllowExperimental(allow);
498 emit allowExperimentalChanged(allow);
502
503
504QGeoServiceProvider *QDeclarativeGeoServiceProvider::sharedGeoServiceProvider()
const
506 return sharedProvider_.get();
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539QStringList QDeclarativeGeoServiceProvider::locales()
const
544void QDeclarativeGeoServiceProvider::setLocales(
const QStringList &locales)
546 if (locales_ == locales)
551 if (locales_.isEmpty())
552 locales_.append(QLocale().name());
555 sharedProvider_->setLocale(QLocale(locales_.at(0)));
557 emit localesChanged();
561
562
563
564
565
566QQmlListProperty<QDeclarativePluginParameter> QDeclarativeGeoServiceProvider::parameters()
568 return QQmlListProperty<QDeclarativePluginParameter>(
this,
577
578
579void QDeclarativeGeoServiceProvider::parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *parameter)
581 QDeclarativeGeoServiceProvider *p =
static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
582 p->parameters_.append(parameter);
583 if (p->sharedProvider_)
584 p->sharedProvider_->setParameters(p->parameterMap());
588
589
590qsizetype QDeclarativeGeoServiceProvider::parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop)
592 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_.count();
596
597
598QDeclarativePluginParameter *QDeclarativeGeoServiceProvider::parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, qsizetype index)
600 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_[index];
604
605
606void QDeclarativeGeoServiceProvider::parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop)
608 QDeclarativeGeoServiceProvider *p =
static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
609 p->parameters_.clear();
610 if (p->sharedProvider_)
611 p->sharedProvider_->setParameters(p->parameterMap());
615
616
617QVariantMap QDeclarativeGeoServiceProvider::parameterMap()
const
621 for (
const auto *parameter : parameters_)
622 map.insert(parameter->name(), parameter->value());
628
630QDeclarativeGeoServiceProviderRequirements::QDeclarativeGeoServiceProviderRequirements(QObject *parent)
635QDeclarativeGeoServiceProviderRequirements::~QDeclarativeGeoServiceProviderRequirements()
640
641
642QDeclarativeGeoServiceProvider::MappingFeatures QDeclarativeGeoServiceProviderRequirements::mappingRequirements()
const
648
649
650void QDeclarativeGeoServiceProviderRequirements::setMappingRequirements(
const QDeclarativeGeoServiceProvider::MappingFeatures &features)
652 if (mapping_ == features)
656 emit mappingRequirementsChanged(mapping_);
657 emit requirementsChanged();
661
662
663QDeclarativeGeoServiceProvider::RoutingFeatures QDeclarativeGeoServiceProviderRequirements::routingRequirements()
const
669
670
671void QDeclarativeGeoServiceProviderRequirements::setRoutingRequirements(
const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
673 if (routing_ == features)
677 emit routingRequirementsChanged(routing_);
678 emit requirementsChanged();
682
683
684QDeclarativeGeoServiceProvider::GeocodingFeatures QDeclarativeGeoServiceProviderRequirements::geocodingRequirements()
const
690
691
692void QDeclarativeGeoServiceProviderRequirements::setGeocodingRequirements(
const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
694 if (geocoding_ == features)
697 geocoding_ = features;
698 emit geocodingRequirementsChanged(geocoding_);
699 emit requirementsChanged();
703
704
705
706QDeclarativeGeoServiceProvider::PlacesFeatures QDeclarativeGeoServiceProviderRequirements::placesRequirements()
const
712
713
714void QDeclarativeGeoServiceProviderRequirements::setPlacesRequirements(
const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
716 if (places_ == features)
720 emit placesRequirementsChanged(places_);
721 emit requirementsChanged();
725
726
727QDeclarativeGeoServiceProvider::NavigationFeatures QDeclarativeGeoServiceProviderRequirements::navigationRequirements()
const
733
734
735void QDeclarativeGeoServiceProviderRequirements::setNavigationRequirements(
const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
737 if (navigation_ == features)
740 navigation_ = features;
741 emit navigationRequirementsChanged(navigation_);
742 emit requirementsChanged();
746
747
748bool QDeclarativeGeoServiceProviderRequirements::matches(
const QGeoServiceProvider *provider)
const
750 QGeoServiceProvider::MappingFeatures mapping =
751 static_cast<QGeoServiceProvider::MappingFeatures>(
int(mapping_));
755 if (mapping == QGeoServiceProvider::AnyMappingFeatures) {
756 if (provider->mappingFeatures() == QGeoServiceProvider::NoMappingFeatures)
759 if ((provider->mappingFeatures() & mapping) != mapping)
763 QGeoServiceProvider::RoutingFeatures routing =
764 static_cast<QGeoServiceProvider::RoutingFeatures>(
int(routing_));
766 if (routing == QGeoServiceProvider::AnyRoutingFeatures) {
767 if (provider->routingFeatures() == QGeoServiceProvider::NoRoutingFeatures)
770 if ((provider->routingFeatures() & routing) != routing)
774 QGeoServiceProvider::GeocodingFeatures geocoding =
775 static_cast<QGeoServiceProvider::GeocodingFeatures>(
int(geocoding_));
777 if (geocoding == QGeoServiceProvider::AnyGeocodingFeatures) {
778 if (provider->geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures)
781 if ((provider->geocodingFeatures() & geocoding) != geocoding)
785 QGeoServiceProvider::PlacesFeatures places =
786 static_cast<QGeoServiceProvider::PlacesFeatures>(
int(places_));
788 if (places == QGeoServiceProvider::AnyPlacesFeatures) {
789 if (provider->placesFeatures() == QGeoServiceProvider::NoPlacesFeatures)
792 if ((provider->placesFeatures() & places) != places)
796 QGeoServiceProvider::NavigationFeatures navigation =
797 static_cast<QGeoServiceProvider::NavigationFeatures>(
int(navigation_));
799 if (navigation == QGeoServiceProvider::AnyNavigationFeatures) {
800 if (provider->navigationFeatures() == QGeoServiceProvider::NoNavigationFeatures)
803 if ((provider->navigationFeatures() & navigation) != navigation)
810bool QDeclarativeGeoServiceProviderRequirements::operator == (
const QDeclarativeGeoServiceProviderRequirements &rhs)
const
812 return (mapping_ == rhs.mapping_ && routing_ == rhs.routing_
813 && geocoding_ == rhs.geocoding_ && places_ == rhs.places_
814 && navigation_ == rhs.navigation_);
818
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
841
842
843
844
845
848
849
850
851
852
855
856