8#include <QJsonDocument>
11#include <QtCore/QUrlQuery>
13#include <QtPositioning/QGeoRectangle>
14#include <QtPositioning/QGeoShape>
16#include <QtLocation/QPlaceCategory>
17#include <QtLocation/QPlaceSearchRequest>
36 "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer?f=pjson");
38 "GeocodeServer/findAddressCandidates");
67 bool unsupported =
false;
72 unsupported |=
request.searchTerm().isEmpty() &&
request.categories().isEmpty();
98 if (!
request.searchTerm().isEmpty())
102 if (!
request.categories().isEmpty())
105 categories.append(placeCategory.categoryId());
123 this, &PlaceManagerEngineEsri::replyFinished);
125 this, &PlaceManagerEngineEsri::replyError);
130void PlaceManagerEngineEsri::replyFinished()
148 initializeGeocodeServer();
152 this, &PlaceManagerEngineEsri::replyFinished);
154 this, &PlaceManagerEngineEsri::replyError);
158 reply->emitFinished();
164void PlaceManagerEngineEsri::parseCategories(
const QJsonArray &jsonArray,
const QString &parentCategoryId)
168 if (!jsonValue.isObject())
171 const QJsonObject jsonCategory = jsonValue.toObject();
173 const QString localeName = localizedName(jsonCategory);
189 parseCategories(jsonArray,
key);
196 return m_parentCategory.
value(categoryId);
201 return m_subcategories.
value(categoryId);
206 return m_categories.
value(categoryId);
212 for (
const QString &
id : m_subcategories.
value(parentId))
217void PlaceManagerEngineEsri::finishCategories()
220 reply->emitFinished();
221 m_pendingCategoriesReply.
clear();
224void PlaceManagerEngineEsri::errorCaterogies(
const QString &
error)
232void PlaceManagerEngineEsri::initializeGeocodeServer()
235 if (m_categories.
isEmpty() && !m_geocodeServerReply)
239 this, &PlaceManagerEngineEsri::geocodeServerReplyFinished);
241 this, &PlaceManagerEngineEsri::geocodeServerReplyError);
249 for (
const QLocale &locale :
std::as_const(m_locales)) {
251 if (localizedNames.
contains(localeStr))
257 if (localizedNames.
contains(shortLocale))
265void PlaceManagerEngineEsri::parseCandidateFields(
const QJsonArray &jsonArray)
269 if (!jsonValue.isObject())
272 const QJsonObject jsonCandidateField = jsonValue.toObject();
277 m_candidateFieldsLocale.
insert(
key, localizedName(jsonCandidateField));
281void PlaceManagerEngineEsri::parseCountries(
const QJsonArray &jsonArray)
285 if (!jsonValue.isObject())
288 const QJsonObject jsonCountry = jsonValue.toObject();
293 m_countriesLocale.
insert(
key, localizedName(jsonCountry));
297void PlaceManagerEngineEsri::geocodeServerReplyFinished()
299 if (!m_geocodeServerReply)
305 errorCaterogies(m_geocodeServerReply->
errorString());
315 parseCategories(jsonArray,
QString());
322 parseCandidateFields(jsonArray);
329 parseCountries(jsonArray);
337void PlaceManagerEngineEsri::geocodeServerReplyError()
339 if (m_categories.
isEmpty() && !m_geocodeServerReply)
342 errorCaterogies(m_geocodeServerReply->
errorString());
QPlaceReply * initializeCategories() override
Initializes the categories of the manager engine.
QStringList childCategoryIds(const QString &categoryId) const override
Returns the child category identifiers of the category corresponding to categoryId.
QPlaceSearchReply * search(const QPlaceSearchRequest &request) override
Searches for places according to the parameters specified in request.
QList< QPlaceCategory > childCategories(const QString &parentId) const override
Returns a list of categories that are children of the category corresponding to parentId.
QList< QLocale > locales() const override
Returns a list of preferred locales.
~PlaceManagerEngineEsri()
void setLocales(const QList< QLocale > &locales) override
Set the list of preferred locales.
PlaceManagerEngineEsri(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString)
QPlaceCategory category(const QString &categoryId) const override
Returns the category corresponding to the given categoryId.
QString parentCategoryId(const QString &categoryId) const override
Returns the parent category identifier of the category corresponding to categoryId.
double longitude
This property holds the longitude in decimal degrees.
double latitude
This property holds the latitude in decimal degrees.
QGeoCoordinate topLeft
This property holds the top left coordinate of this geo rectangle.
QGeoCoordinate bottomRight
This property holds the bottom right coordinate of this geo rectangle.
Error
Describes an error related to the loading and setup of a service provider plugin.
bool isEmpty
This property defines whether this geo shape is empty.
T value(const Key &key) const noexcept
bool isEmpty() const noexcept
Returns true if the hash contains no items; otherwise returns false.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
QString errorString() const
Returns a human-readable description of the last device error that occurred.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
static QJsonDocument fromJson(const QByteArray &json, QJsonParseError *error=nullptr)
Parses json as a UTF-8 encoded JSON document, and creates a QJsonDocument from it.
\inmodule QtCore\reentrant
QJsonValue value(const QString &key) const
Returns a QJsonValue representing the value for the key key.
bool contains(const QString &key) const
Returns true if the object contains key key.
QJsonObject toObject() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QJsonArray toArray() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString toString() const
Converts the value to a QString and returns it.
void append(parameter_type t)
The QNetworkAccessManager class allows the application to send network requests and receive replies.
QNetworkReply * get(const QNetworkRequest &request)
Posts a request to obtain the contents of the target request and returns a new QNetworkReply object o...
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void errorOccurred(QNetworkReply::NetworkError)
void finished()
This signal is emitted when the reply has finished processing.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
@ RedirectPolicyAttribute
void setAttribute(Attribute code, const QVariant &value)
Sets the attribute associated with code code to be value value.
@ NoLessSafeRedirectPolicy
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
void deleteLater()
\threadsafe
void finished(QPlaceReply *reply)
This signal is emitted when reply has finished processing.
virtual QPlaceSearchReply * search(const QPlaceSearchRequest &request)
Searches for places according to the parameters specified in request.
void errorOccurred(QPlaceReply *, QPlaceReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of reply.
void categoryAdded(const QPlaceCategory &category, const QString &parentCategoryId)
This signal is emitted if a category has been added to the manager engine's datastore.
void errorOccurred(QPlaceReply::Error error, const QString &errorString=QString())
This signal is emitted when an error has been detected in the processing of this reply.
void finished()
This signal is emitted when this reply has finished processing.
Error
Describes an error which occurred during an operation.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void clear()
Clears the contents of the string and makes it null.
QString arg(qlonglong a, int fieldwidth=0, int base=10, QChar fillChar=u' ') const
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
QString left(qsizetype n) const
Returns a substring that contains the n leftmost characters of the string.
void addQueryItem(const QString &key, const QString &value)
Appends the pair key = value to the end of the query string of the URL.
void setQuery(const QString &query, ParsingMode mode=TolerantMode)
Sets the query string of the URL to query.
const QLoggingCategory & category()
[1]
Q_QML_PRIVATE_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
Combined button and popup list for selecting options.
emscripten::val document()
static const QString kSingleLineKey(QStringLiteral("singleLine"))
static const QString kCandidateFieldsKey(QStringLiteral("candidateFields"))
static const QString kCountriesKey(QStringLiteral("detailedCountries"))
static const QString kNameKey(QStringLiteral("name"))
static QT_BEGIN_NAMESPACE const QString kCategoriesKey(QStringLiteral("categories"))
static const QUrl kUrlFindAddressCandidates("https://geocode.arcgis.com/arcgis/rest/services/World/" "GeocodeServer/findAddressCandidates")
static const QString kMaxLocationsKey(QStringLiteral("maxLocations"))
static const QUrl kUrlGeocodeServer("https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer?f=pjson")
static const QString kLocalizedNamesKey(QStringLiteral("localizedNames"))
static const QString kLocationKey(QStringLiteral("location"))
static const QString kOutFieldsKey(QStringLiteral("outFields"))
DBusConnection const char DBusError * error
GLsizei GLenum * categories
static void setError(QJsonObject *response, const QString &msg)
#define QStringLiteral(str)
QNetworkRequest request(url)