Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
10
14
58
62
63
64
73{
74 if (name_ == name)
75 return;
76
77 name_ = name;
78
79 if (complete_)
80 tryAttach();
81
82 emit nameChanged(name_);
83}
84
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
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
118{
119 return name_;
120}
121
122
132{
134}
135
140{
141 complete_ = true;
142
143 for (QDeclarativePluginParameter *p: std::as_const(parameters_)) {
144 if (!p->isInitialized()) {
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
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
220bool QDeclarativeGeoServiceProvider::supportsGeocoding(const GeocodingFeatures &feature) const
221{
223 QGeoServiceProvider::GeocodingFeatures f =
224 static_cast<QGeoServiceProvider::GeocodingFeature>(int(feature));
226 return (sp && (sp->geocodingFeatures() != QGeoServiceProvider::NoGeocodingFeatures));
227 else
228 return (sp && (sp->geocodingFeatures() & f) == f);
229}
230
260bool QDeclarativeGeoServiceProvider::supportsMapping(const MappingFeatures &feature) const
261{
263 QGeoServiceProvider::MappingFeatures f =
264 static_cast<QGeoServiceProvider::MappingFeature>(int(feature));
266 return (sp && (sp->mappingFeatures() != QGeoServiceProvider::NoMappingFeatures));
267 else
268 return (sp && (sp->mappingFeatures() & f) == f);
269}
270
309bool QDeclarativeGeoServiceProvider::supportsRouting(const RoutingFeatures &feature) const
310{
312 QGeoServiceProvider::RoutingFeatures f =
313 static_cast<QGeoServiceProvider::RoutingFeature>(int(feature));
315 return (sp && (sp->routingFeatures() != QGeoServiceProvider::NoRoutingFeatures));
316 else
317 return (sp && (sp->routingFeatures() & f) == f);
318}
319
367bool QDeclarativeGeoServiceProvider::supportsPlaces(const PlacesFeatures &feature) const
368{
370 QGeoServiceProvider::PlacesFeatures f =
371 static_cast<QGeoServiceProvider::PlacesFeature>(int(feature));
373 return (sp && (sp->placesFeatures() != QGeoServiceProvider::NoPlacesFeatures));
374 else
375 return (sp && (sp->placesFeatures() & f) == f);
376}
377
404bool QDeclarativeGeoServiceProvider::supportsNavigation(const QDeclarativeGeoServiceProvider::NavigationFeature &feature) const
405{
407 QGeoServiceProvider::NavigationFeatures f =
408 static_cast<QGeoServiceProvider::NavigationFeature>(int(feature));
410 return (sp && (sp->navigationFeatures() != QGeoServiceProvider::NoNavigationFeatures));
411 else
412 return (sp && (sp->navigationFeatures() & f) == f);
413}
414
438
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
459{
460 return prefer_;
461}
462
464{
465 prefer_ = val;
466 emit preferredChanged(prefer_);
467}
468
475{
476 return (sharedProvider_ != 0);
477}
478
485{
486 return experimental_;
487}
488
490{
491 if (experimental_ == allow)
492 return;
493
494 experimental_ = allow;
495 if (sharedProvider_)
496 sharedProvider_->setAllowExperimental(allow);
497
499}
500
505{
506 return sharedProvider_.get();
507}
508
540{
541 return locales_;
542}
543
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
558}
559
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
579void QDeclarativeGeoServiceProvider::parameter_append(QQmlListProperty<QDeclarativePluginParameter> *prop, QDeclarativePluginParameter *parameter)
580{
582 p->parameters_.append(parameter);
583 if (p->sharedProvider_)
584 p->sharedProvider_->setParameters(p->parameterMap());
585}
586
590qsizetype QDeclarativeGeoServiceProvider::parameter_count(QQmlListProperty<QDeclarativePluginParameter> *prop)
591{
592 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_.count();
593}
594
598QDeclarativePluginParameter *QDeclarativeGeoServiceProvider::parameter_at(QQmlListProperty<QDeclarativePluginParameter> *prop, qsizetype index)
599{
600 return static_cast<QDeclarativeGeoServiceProvider *>(prop->object)->parameters_[index];
601}
602
606void QDeclarativeGeoServiceProvider::parameter_clear(QQmlListProperty<QDeclarativePluginParameter> *prop)
607{
609 p->parameters_.clear();
610 if (p->sharedProvider_)
611 p->sharedProvider_->setParameters(p->parameterMap());
612}
613
618{
620
621 for (const auto *parameter : parameters_)
622 map.insert(parameter->name(), parameter->value());
623
624 return map;
625}
626
627/*******************************************************************************
628*******************************************************************************/
629
634
638
642QDeclarativeGeoServiceProvider::MappingFeatures QDeclarativeGeoServiceProviderRequirements::mappingRequirements() const
643{
644 return mapping_;
645}
646
650void QDeclarativeGeoServiceProviderRequirements::setMappingRequirements(const QDeclarativeGeoServiceProvider::MappingFeatures &features)
651{
652 if (mapping_ == features)
653 return;
654
655 mapping_ = features;
658}
659
663QDeclarativeGeoServiceProvider::RoutingFeatures QDeclarativeGeoServiceProviderRequirements::routingRequirements() const
664{
665 return routing_;
666}
667
671void QDeclarativeGeoServiceProviderRequirements::setRoutingRequirements(const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
672{
673 if (routing_ == features)
674 return;
675
676 routing_ = features;
679}
680
684QDeclarativeGeoServiceProvider::GeocodingFeatures QDeclarativeGeoServiceProviderRequirements::geocodingRequirements() const
685{
686 return geocoding_;
687}
688
692void QDeclarativeGeoServiceProviderRequirements::setGeocodingRequirements(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
693{
694 if (geocoding_ == features)
695 return;
696
697 geocoding_ = features;
700}
701
706QDeclarativeGeoServiceProvider::PlacesFeatures QDeclarativeGeoServiceProviderRequirements::placesRequirements() const
707{
708 return places_;
709}
710
714void QDeclarativeGeoServiceProviderRequirements::setPlacesRequirements(const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
715{
716 if (places_ == features)
717 return;
718
719 places_ = features;
722}
723
727QDeclarativeGeoServiceProvider::NavigationFeatures QDeclarativeGeoServiceProviderRequirements::navigationRequirements() const
728{
729 return navigation_;
730}
731
735void QDeclarativeGeoServiceProviderRequirements::setNavigationRequirements(const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
736{
737 if (navigation_ == features)
738 return;
739
740 navigation_ = features;
743}
744
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
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
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
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
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
801 return false;
802 } else {
803 if ((provider->navigationFeatures() & navigation) != navigation)
804 return false;
805 }
806
807 return true;
808}
809
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
823
854/*******************************************************************************
855 * Implementation now in positioningquick
856*******************************************************************************/
857
859
Q_INVOKABLE bool matches(const QGeoServiceProvider *provider) const
void placesRequirementsChanged(const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
QDeclarativeGeoServiceProvider::GeocodingFeatures geocodingRequirements() const
void setMappingRequirements(const QDeclarativeGeoServiceProvider::MappingFeatures &features)
void setGeocodingRequirements(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
void mappingRequirementsChanged(const QDeclarativeGeoServiceProvider::MappingFeatures &features)
void geocodingRequirementsChanged(const QDeclarativeGeoServiceProvider::GeocodingFeatures &features)
void setPlacesRequirements(const QDeclarativeGeoServiceProvider::PlacesFeatures &features)
void setNavigationRequirements(const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
bool operator==(const QDeclarativeGeoServiceProviderRequirements &rhs) const
void navigationRequirementsChanged(const QDeclarativeGeoServiceProvider::NavigationFeatures &features)
QDeclarativeGeoServiceProvider::RoutingFeatures routing
void setRoutingRequirements(const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
QDeclarativeGeoServiceProvider::NavigationFeatures navigation
QDeclarativeGeoServiceProvider::NavigationFeatures navigationRequirements() const
QDeclarativeGeoServiceProvider::PlacesFeatures places
QDeclarativeGeoServiceProvider::RoutingFeatures routingRequirements() const
QDeclarativeGeoServiceProvider::GeocodingFeatures geocoding
void routingRequirementsChanged(const QDeclarativeGeoServiceProvider::RoutingFeatures &features)
QDeclarativeGeoServiceProvider::MappingFeatures mapping
QDeclarativeGeoServiceProvider::MappingFeatures mappingRequirements() const
QDeclarativeGeoServiceProvider::PlacesFeatures placesRequirements() const
void setRequirements(QDeclarativeGeoServiceProviderRequirements *req)
QStringList availableServiceProviders
\qmlproperty stringlist Plugin::availableServiceProviders
Q_INVOKABLE bool supportsRouting(const RoutingFeatures &feature=AnyRoutingFeatures) const
\qmlmethod bool Plugin::supportsRouting(RoutingFeatures features)
Q_INVOKABLE bool supportsMapping(const MappingFeatures &feature=AnyMappingFeatures) const
\qmlmethod bool Plugin::supportsMapping(MappingFeatures features)
QDeclarativeGeoServiceProvider(QObject *parent=nullptr)
The Plugin type describes a Location based services plugin.
QDeclarativeGeoServiceProviderRequirements * requirements() const
\qmlproperty enumeration Plugin::required
void preferredChanged(const QStringList &preferences)
void nameChanged(const QString &name)
QQmlListProperty< QDeclarativePluginParameter > parameters
\qmlproperty list<PluginParameter> Plugin::parameters \qmldefault
void setName(const QString &name)
\qmlproperty string Plugin::name
Q_INVOKABLE bool supportsPlaces(const PlacesFeatures &feature=AnyPlacesFeatures) const
\qmlmethod bool Plugin::supportsPlaces(PlacesFeatures features)
void allowExperimentalChanged(bool allow)
void setLocales(const QStringList &locales)
Q_INVOKABLE bool supportsGeocoding(const GeocodingFeatures &feature=AnyGeocodingFeatures) const
\qmlmethod bool Plugin::supportsGeocoding(GeocodingFeatures features)
QGeoServiceProvider * sharedGeoServiceProvider() const
\inmodule QtLocation
RoutingFeature
Describes the routing features supported by the geo service provider.
MappingFeatures mappingFeatures() const
Returns the mapping features supported by the geo service provider.
MappingFeature
Describes the mapping features supported by the geo service provider.
PlacesFeature
Describes the places features supported by the geo service provider.
GeocodingFeature
Describes the geocoding features supported by the geo service provider.
PlacesFeatures placesFeatures() const
Returns the places features supported by the geo service provider.
RoutingFeatures routingFeatures() const
Returns the routing features supported by the geo service provider.
static QStringList availableServiceProviders()
GeocodingFeatures geocodingFeatures() const
Returns the geocoding features supported by the geo service provider.
NavigationFeatures navigationFeatures() const
Returns the navigation features supported by the geo service provider.
NavigationFeature
Describes the navigation features supported by the geo service provider.
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
qsizetype count() const noexcept
Definition qlist.h:398
void append(parameter_type t)
Definition qlist.h:458
void clear()
Definition qlist.h:434
iterator insert(const Key &key, const T &value)
Definition qmap.h:688
\inmodule QtCore
Definition qobject.h:103
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
GLuint index
[2]
GLfloat GLfloat f
GLuint name
GLuint GLfloat * val
GLenum GLenum GLenum GLenum mapping
GLfloat GLfloat p
[1]
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define sp
#define emit
ptrdiff_t qsizetype
Definition qtypes.h:165