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
qgeocodereplymapbox.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 Mapbox, Inc.
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 "qmapboxcommon.h"
6
7#include <QtCore/QJsonDocument>
8#include <QtCore/QJsonObject>
9#include <QtCore/QJsonArray>
10#include <QtPositioning/QGeoCoordinate>
11#include <QtPositioning/QGeoAddress>
12#include <QtPositioning/QGeoLocation>
13#include <QtPositioning/QGeoRectangle>
14
16
18: QGeoCodeReply(parent)
19{
21 if (!reply) {
22 setError(UnknownError, QStringLiteral("Null reply"));
23 return;
24 }
25
26 connect(reply, &QNetworkReply::finished, this, &QGeoCodeReplyMapbox::onNetworkReplyFinished);
27 connect(reply, &QNetworkReply::errorOccurred, this, &QGeoCodeReplyMapbox::onNetworkReplyError);
28
31}
32
36
37void QGeoCodeReplyMapbox::onNetworkReplyFinished()
38{
39 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
41
43 return;
44
45 QList<QGeoLocation> locations;
47 if (!document.isObject()) {
48 setError(ParseError, tr("Response parse error"));
49 return;
50 }
51
52 const QJsonArray features = document.object().value(QStringLiteral("features")).toArray();
53 for (const QJsonValueConstRef value : features)
54 locations.append(QMapboxCommon::parseGeoLocation(value.toObject()));
55
57
58 setFinished(true);
59}
60
61void QGeoCodeReplyMapbox::onNetworkReplyError(QNetworkReply::NetworkError error)
62{
64 QNetworkReply *reply = static_cast<QNetworkReply *>(sender());
67}
68
QGeoCodeReplyMapbox(QNetworkReply *reply, QObject *parent=nullptr)
\inmodule QtLocation
Error error() const
Returns the error state of this reply.
void setFinished(bool finished)
Sets whether or not this reply has finished to finished.
void setError(Error error, const QString &errorString)
Sets the error state of this reply to error and the textual representation of the error to errorStrin...
QList< QGeoLocation > locations() const
Returns a list of locations.
void setLocations(const QList< QGeoLocation > &locations)
Sets the list of locations in the reply.
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
Definition qjsonarray.h:18
\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.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
void errorOccurred(QNetworkReply::NetworkError)
NetworkError error() const
Returns the error that was found during the processing of this request.
virtual void abort()=0
Aborts the operation immediately and close down any network connections still open.
NetworkError
Indicates all possible error conditions found during the processing of the request.
void finished()
This signal is emitted when the reply has finished processing.
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
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
QObject * sender() const
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; othe...
Definition qobject.cpp:2658
void destroyed(QObject *=nullptr)
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointe...
void deleteLater()
\threadsafe
Definition qobject.cpp:2435
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
emscripten::val document()
Definition qwasmdom.h:49
DBusConnection const char DBusError * error
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLuint const GLint * locations
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define QStringLiteral(str)
#define tr(X)
#define Q_UNUSED(x)
QNetworkReply * reply