6#include <QtQml/QQmlInfo>
7#include <QtQml/QQmlEngine>
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
52
54QDeclarativeGeoServiceProvider::QDeclarativeGeoServiceProvider(QObject *parent)
55: QObject(parent), required_(
new QDeclarativeGeoServiceProviderRequirements)
57 locales_.append(QLocale().name());
60QDeclarativeGeoServiceProvider::~QDeclarativeGeoServiceProvider()
67
68
69
70
71
72
73void QDeclarativeGeoServiceProvider::setName(
const QString &name)
83 emit nameChanged(name_);
87
88
89bool QDeclarativeGeoServiceProvider::parametersReady() {
90 for (
const QDeclarativePluginParameter *p: std::as_const(parameters_)) {
91 if (!p->isInitialized())
98
99
100void QDeclarativeGeoServiceProvider::tryAttach()
102 if (!parametersReady())
105 sharedProvider_.reset();
110 sharedProvider_.reset(
new QGeoServiceProvider(name_, parameterMap()));
111 sharedProvider_->setQmlEngine(qmlEngine(
this));
112 sharedProvider_->setLocale(QLocale(locales_.at(0)));
113 sharedProvider_->setAllowExperimental(experimental_);
118QString QDeclarativeGeoServiceProvider::name()
const
125
126
127
128
129
130
131
132QStringList QDeclarativeGeoServiceProvider::availableServiceProviders()
134 return QGeoServiceProvider::availableServiceProviders();
138
139
140void QDeclarativeGeoServiceProvider::componentComplete()
144 for (QDeclarativePluginParameter *p: std::as_const(parameters_)) {
145 if (!p->isInitialized()) {
146 connect(p, &QDeclarativePluginParameter::initialized,
147 this, &QDeclarativeGeoServiceProvider::tryAttach);
151 if (!name_.isEmpty()) {
153 }
else if (!prefer_.isEmpty()
154 || required_->mappingRequirements() != NoMappingFeatures
155 || required_->routingRequirements() != NoRoutingFeatures
156 || required_->geocodingRequirements() != NoGeocodingFeatures
157 || required_->placesRequirements() != NoPlacesFeatures
158 || required_->navigationRequirements() != NoNavigationFeatures) {
160 QStringList providers = QGeoServiceProvider::availableServiceProviders();
163 for (
const QString &name : std::as_const(prefer_)) {
164 if (providers.contains(name)) {
166 providers.removeAll(name);
168 QGeoServiceProvider sp(name, parameterMap(), experimental_);
169 if (required_->matches(&sp)) {
177 for (
const QString &name : std::as_const(providers)) {
178 QGeoServiceProvider sp(name, parameterMap(), experimental_);
179 if (required_->matches(&sp)) {
185 qmlWarning(
this) <<
"Could not find a plugin with the required features to attach to";
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
220
221bool QDeclarativeGeoServiceProvider::supportsGeocoding(
const GeocodingFeatures &feature)
const
223 QGeoServiceProvider *sp = sharedGeoServiceProvider();
224 QGeoServiceProvider::GeocodingFeatures f =
225 static_cast<QGeoServiceProvider::GeocodingFeature>(
int(feature));
226 if (f == QGeoServiceProvider::AnyGeocodingFeatures)
227 return (sp && (sp->geocodingFeatures() != QGeoServiceProvider::NoGeocodingFeatures));
229 return (sp && (sp->geocodingFeatures() & f) == f);
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
260
261bool QDeclarativeGeoServiceProvider::supportsMapping(
const MappingFeatures &feature)
const
263 QGeoServiceProvider *sp = sharedGeoServiceProvider();
264 QGeoServiceProvider::MappingFeatures f =
265 static_cast<QGeoServiceProvider::MappingFeature>(
int(feature));
266 if (f == QGeoServiceProvider::AnyMappingFeatures)
267 return (sp && (sp->mappingFeatures() != QGeoServiceProvider::NoMappingFeatures));
269 return (sp && (sp->mappingFeatures() & f) == f);
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
309
310bool QDeclarativeGeoServiceProvider::supportsRouting(
const RoutingFeatures &feature)
const
312 QGeoServiceProvider *sp = sharedGeoServiceProvider();
313 QGeoServiceProvider::RoutingFeatures f =
314 static_cast<QGeoServiceProvider::RoutingFeature>(
int(feature));
315 if (f == QGeoServiceProvider::AnyRoutingFeatures)
316 return (sp && (sp->routingFeatures() != QGeoServiceProvider::NoRoutingFeatures));
318 return (sp && (sp->routingFeatures() & f) == f);
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
367
368bool QDeclarativeGeoServiceProvider::supportsPlaces(
const PlacesFeatures &feature)
const
370 QGeoServiceProvider *sp = sharedGeoServiceProvider();
371 QGeoServiceProvider::PlacesFeatures f =
372 static_cast<QGeoServiceProvider::PlacesFeature>(
int(feature));
373 if (f == QGeoServiceProvider::AnyPlacesFeatures)
374 return (sp && (sp->placesFeatures() != QGeoServiceProvider::NoPlacesFeatures));
376 return (sp && (sp->placesFeatures() & f) == f);
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405bool QDeclarativeGeoServiceProvider::supportsNavigation(
const QDeclarativeGeoServiceProvider::NavigationFeature &feature)
const
407 QGeoServiceProvider *sp = sharedGeoServiceProvider();
408 QGeoServiceProvider::NavigationFeatures f =
409 static_cast<QGeoServiceProvider::NavigationFeature>(
int(feature));
410 if (f == QGeoServiceProvider::AnyNavigationFeatures)
411 return (sp && (sp->navigationFeatures() != QGeoServiceProvider::NoNavigationFeatures));
413 return (sp && (sp->navigationFeatures() & f) == f);
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435QDeclarativeGeoServiceProviderRequirements *QDeclarativeGeoServiceProvider::requirements()
const
437 return required_.get();
440void QDeclarativeGeoServiceProvider::setRequirements(QDeclarativeGeoServiceProviderRequirements *req)
442 if (!name().isEmpty() || !req)
445 if (required_ && *required_ == *req)
448 required_.reset(req);
449 QQmlEngine::setObjectOwnership(req, QQmlEngine::CppOwnership);
453
454
455
456
457
458
459QStringList QDeclarativeGeoServiceProvider::preferred()
const
464void QDeclarativeGeoServiceProvider::setPreferred(
const QStringList &val)
467 emit preferredChanged(prefer_);
471
472
473
474
475bool QDeclarativeGeoServiceProvider::isAttached()
const
477 return (sharedProvider_ != 0);
481
482
483
484
485bool QDeclarativeGeoServiceProvider::allowExperimental()
const
487 return experimental_;
490void QDeclarativeGeoServiceProvider::setAllowExperimental(
bool allow)
492 if (experimental_ == allow)
495 experimental_ = allow;
497 sharedProvider_->setAllowExperimental(allow);
499 emit allowExperimentalChanged(allow);
503
504
505QGeoServiceProvider *QDeclarativeGeoServiceProvider::sharedGeoServiceProvider()
const
507 return sharedProvider_.get();
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
539
540QStringList QDeclarativeGeoServiceProvider::locales()
const
545void QDeclarativeGeoServiceProvider::setLocales(
const QStringList &locales)
547 if (locales_ == locales)
552 if (locales_.isEmpty())
553 locales_.append(QLocale().name());
556 sharedProvider_->setLocale(QLocale(locales_.at(0)));
558 emit localesChanged();
562
563
564
565
566
567QQmlListProperty<QDeclarativePluginParameter> QDeclarativeGeoServiceProvider::parameters()
569 return QQmlListProperty<QDeclarativePluginParameter>(
this,
578
579
580void QDeclarativeGeoServiceProvider::parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *parameter)
582 QDeclarativeGeoServiceProvider *p =
static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
583 p->parameters_.append(parameter);
584 if (p->sharedProvider_)
585 p->sharedProvider_->setParameters(p->parameterMap());
589
590
591qsizetype QDeclarativeGeoServiceProvider::parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop)
593 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_.count();
597
598
599QDeclarativePluginParameter *QDeclarativeGeoServiceProvider::parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, qsizetype index)
601 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_[index];
605
606
607void QDeclarativeGeoServiceProvider::parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop)
609 QDeclarativeGeoServiceProvider *p =
static_cast<QDeclarativeGeoServiceProvider *>(prop->object);
610 p->parameters_.clear();
611 if (p->sharedProvider_)
612 p->sharedProvider_->setParameters(p->parameterMap());
616
617
618QVariantMap QDeclarativeGeoServiceProvider::parameterMap()
const
622 for (
const auto *parameter : parameters_)
623 map.insert(parameter->name(), parameter->value());
629
631QDeclarativeGeoServiceProviderRequirements::QDeclarativeGeoServiceProviderRequirements(QObject *parent)
636QDeclarativeGeoServiceProviderRequirements::~QDeclarativeGeoServiceProviderRequirements()
641
642
643QDeclarativeGeoServiceProvider::MappingFeatures QDeclarativeGeoServiceProviderRequirements::mappingRequirements()
const
649
650
651void QDeclarativeGeoServiceProviderRequirements::setMappingRequirements(
const QDeclarativeGeoServiceProvider::MappingFeatures &features)
653 if (mapping_ == features)
657 emit mappingRequirementsChanged(mapping_);
658 emit requirementsChanged();
662
663
664QDeclarativeGeoServiceProvider::RoutingFeatures QDeclarativeGeoServiceProviderRequirements::routingRequirements()
const
670
671
672void QDeclarativeGeoServiceProviderRequirements::setRoutingRequirements(
const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
674 if (routing_ == features)
678 emit routingRequirementsChanged(routing_);
679 emit requirementsChanged();
683
684
685QDeclarativeGeoServiceProvider::GeocodingFeatures QDeclarativeGeoServiceProviderRequirements::geocodingRequirements()
const
691
692
693void QDeclarativeGeoServiceProviderRequirements::setGeocodingRequirements(
const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
695 if (geocoding_ == features)
698 geocoding_ = features;
699 emit geocodingRequirementsChanged(geocoding_);
700 emit requirementsChanged();
704
705
706
707QDeclarativeGeoServiceProvider::PlacesFeatures QDeclarativeGeoServiceProviderRequirements::placesRequirements()
const
713
714
715void QDeclarativeGeoServiceProviderRequirements::setPlacesRequirements(
const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
717 if (places_ == features)
721 emit placesRequirementsChanged(places_);
722 emit requirementsChanged();
726
727
728QDeclarativeGeoServiceProvider::NavigationFeatures QDeclarativeGeoServiceProviderRequirements::navigationRequirements()
const
734
735
736void QDeclarativeGeoServiceProviderRequirements::setNavigationRequirements(
const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
738 if (navigation_ == features)
741 navigation_ = features;
742 emit navigationRequirementsChanged(navigation_);
743 emit requirementsChanged();
747
748
749bool QDeclarativeGeoServiceProviderRequirements::matches(
const QGeoServiceProvider *provider)
const
751 QGeoServiceProvider::MappingFeatures mapping =
752 static_cast<QGeoServiceProvider::MappingFeatures>(
int(mapping_));
756 if (mapping == QGeoServiceProvider::AnyMappingFeatures) {
757 if (provider->mappingFeatures() == QGeoServiceProvider::NoMappingFeatures)
760 if ((provider->mappingFeatures() & mapping) != mapping)
764 QGeoServiceProvider::RoutingFeatures routing =
765 static_cast<QGeoServiceProvider::RoutingFeatures>(
int(routing_));
767 if (routing == QGeoServiceProvider::AnyRoutingFeatures) {
768 if (provider->routingFeatures() == QGeoServiceProvider::NoRoutingFeatures)
771 if ((provider->routingFeatures() & routing) != routing)
775 QGeoServiceProvider::GeocodingFeatures geocoding =
776 static_cast<QGeoServiceProvider::GeocodingFeatures>(
int(geocoding_));
778 if (geocoding == QGeoServiceProvider::AnyGeocodingFeatures) {
779 if (provider->geocodingFeatures() == QGeoServiceProvider::NoGeocodingFeatures)
782 if ((provider->geocodingFeatures() & geocoding) != geocoding)
786 QGeoServiceProvider::PlacesFeatures places =
787 static_cast<QGeoServiceProvider::PlacesFeatures>(
int(places_));
789 if (places == QGeoServiceProvider::AnyPlacesFeatures) {
790 if (provider->placesFeatures() == QGeoServiceProvider::NoPlacesFeatures)
793 if ((provider->placesFeatures() & places) != places)
797 QGeoServiceProvider::NavigationFeatures navigation =
798 static_cast<QGeoServiceProvider::NavigationFeatures>(
int(navigation_));
800 if (navigation == QGeoServiceProvider::AnyNavigationFeatures) {
801 if (provider->navigationFeatures() == QGeoServiceProvider::NoNavigationFeatures)
804 if ((provider->navigationFeatures() & navigation) != navigation)
811bool QDeclarativeGeoServiceProviderRequirements::operator == (
const QDeclarativeGeoServiceProviderRequirements &rhs)
const
813 return (mapping_ == rhs.mapping_ && routing_ == rhs.routing_
814 && geocoding_ == rhs.geocoding_ && places_ == rhs.places_
815 && navigation_ == rhs.navigation_);
819
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
842
843
844
845
846
849
850
851
852
853
856
857