8#include <QtCore/QElapsedTimer>
9#include <QtCore/QLocale>
10#include <QtCore/QRegularExpression>
11#include <QtCore/QUrlQuery>
12#include <QtCore/QXmlStreamReader>
14#include <QtNetwork/QNetworkAccessManager>
15#include <QtNetwork/QNetworkRequest>
16#include <QtNetwork/QNetworkReply>
18#include <QtPositioning/QGeoCircle>
20#include <QtLocation/QPlaceCategory>
21#include <QtLocation/QPlaceSearchRequest>
22#include <QtLocation/private/unsupportedreplies_p.h>
26QString SpecialPhrasesBaseUrl =
QStringLiteral(
"http://wiki.openstreetmap.org/wiki/Special:Export/Nominatim/Special_Phrases/");
31 return QPlaceManagerEngineOsm::tr(
"Aeroway");
33 return QPlaceManagerEngineOsm::tr(
"Amenity");
35 return QPlaceManagerEngineOsm::tr(
"Building");
37 return QPlaceManagerEngineOsm::tr(
"Highway");
39 return QPlaceManagerEngineOsm::tr(
"Historic");
41 return QPlaceManagerEngineOsm::tr(
"Land use");
43 return QPlaceManagerEngineOsm::tr(
"Leisure");
45 return QPlaceManagerEngineOsm::tr(
"Man made");
47 return QPlaceManagerEngineOsm::tr(
"Natural");
49 return QPlaceManagerEngineOsm::tr(
"Place");
51 return QPlaceManagerEngineOsm::tr(
"Railway");
53 return QPlaceManagerEngineOsm::tr(
"Shop");
55 return QPlaceManagerEngineOsm::tr(
"Tourism");
57 return QPlaceManagerEngineOsm::tr(
"Waterway");
73 m_userAgent =
"Qt Location based application";
78 m_urlPrefix =
QStringLiteral(
"http://nominatim.openstreetmap.org/search");
98 bool unsupported =
false;
103 unsupported |=
request.searchTerm().isEmpty() &&
request.categories().isEmpty();
127 if (!
request.searchTerm().isEmpty())
128 queryParts.append(
request.searchTerm());
140 if (!placeIds.isEmpty())
147 QUrl requestUrl(m_urlPrefix);
156 this, &QPlaceManagerEngineOsm::replyFinished);
158 this, &QPlaceManagerEngineOsm::replyError);
169 if (m_categories.
isEmpty() && !m_categoriesReply) {
170 m_categoryLocales = m_locales;
172 fetchNextCategoryLocale();
177 this, &QPlaceManagerEngineOsm::replyFinished);
179 this, &QPlaceManagerEngineOsm::replyError);
183 reply->emitFinished();
199 return m_subcategories.
value(categoryId);
204 return m_categories.
value(categoryId);
210 for (
const QString &
id : m_subcategories.
value(parentId))
225void QPlaceManagerEngineOsm::categoryReplyFinished()
230 QXmlStreamReader parser(
reply);
231 while (!parser.atEnd() && parser.readNextStartElement()) {
243 while (
i.hasNext()) {
255 if (!m_categories.
contains(tagKey)) {
258 category.setName(nameForTagKey(tagKey));
260 m_subcategories[
QString()].append(tagKey);
270 m_subcategories[tagKey].append(
category.categoryId());
276 parser.skipCurrentElement();
280 fetchNextCategoryLocale();
283 m_categoryLocales.
clear();
287 reply->emitFinished();
288 m_pendingCategoriesReply.
clear();
291void QPlaceManagerEngineOsm::categoryReplyError()
297void QPlaceManagerEngineOsm::replyFinished()
311void QPlaceManagerEngineOsm::fetchNextCategoryLocale()
313 if (m_categoryLocales.
isEmpty()) {
314 qWarning(
"No locales specified to fetch categories for");
321 QUrl requestUrl =
QUrl(SpecialPhrasesBaseUrl +
locale.name().left(2).toUpper());
325 this, &QPlaceManagerEngineOsm::categoryReplyFinished);
327 this, &QPlaceManagerEngineOsm::categoryReplyError);
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.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
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.
bool isEmpty() const noexcept
void append(parameter_type t)
T value(const Key &key, const T &defaultValue=T()) const
bool contains(const Key &key) const
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
QStringList childCategoryIds(const QString &categoryId) const override
Returns the child category identifiers of the category corresponding to categoryId.
QPlaceReply * initializeCategories() override
Initializes the categories of the manager engine.
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.
QPlaceCategory category(const QString &categoryId) const override
Returns the category corresponding to the given categoryId.
QPlaceSearchReply * search(const QPlaceSearchRequest &request) override
Searches for places according to the parameters specified in request.
QString parentCategoryId(const QString &categoryId) const override
Returns the parent category identifier of the category corresponding to categoryId.
QPlaceManagerEngineOsm(const QVariantMap ¶meters, QGeoServiceProvider::Error *error, QString *errorString)
void setLocales(const QList< QLocale > &locales) override
Set the list of preferred locales.
~QPlaceManagerEngineOsm()
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.
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
QByteArray toLatin1() const &
void clear()
Clears the contents of the string and makes it null.
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void addQueryItem(const QString &key, const QString &value)
Appends the pair key = value to the end of the query string of the URL.
QString url(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
void setQuery(const QString &query, ParsingMode mode=TolerantMode)
Sets the query string of the URL to query.
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
const QLoggingCategory & category()
[1]
Q_QML_PRIVATE_EXPORT QV4::ReturnedValue locale(QV4::ExecutionEngine *engine, const QString &localeName)
Provides locale specific properties and formatted data.
DBusConnection const char DBusError * error
GLsizei GLenum * categories
static void setError(QJsonObject *response, const QString &msg)
QLatin1StringView QLatin1String
#define QStringLiteral(str)
static QStringList toStringList(const QJsonArray &jsonArray)
static bool match(const uchar *found, uint foundLen, const char *target, uint targetLen)
QNetworkRequest request(url)
\inmodule QtCore \reentrant