Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qplacesearchsuggestionreplymapbox.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
4
#
include
"qplacesearchsuggestionreplymapbox.h"
5
#
include
"qplacemanagerenginemapbox.h"
6
7
#
include
<
QtCore
/
QJsonDocument
>
8
#
include
<
QtCore
/
QJsonArray
>
9
#
include
<
QtCore
/
QJsonObject
>
10
#
include
<
QtNetwork
/
QNetworkReply
>
11
#
include
<
QtPositioning
/
QGeoCircle
>
12
#
include
<
QtPositioning
/
QGeoRectangle
>
13
#
include
<
QtLocation
/
QPlaceResult
>
14
#
include
<
QtLocation
/
QPlaceSearchRequest
>
15
16
QT_BEGIN_NAMESPACE
17
18
QPlaceSearchSuggestionReplyMapbox
::
QPlaceSearchSuggestionReplyMapbox
(
QNetworkReply
*
reply
,
QPlaceManagerEngineMapbox
*
parent
)
19
:
QPlaceSearchSuggestionReply
(
parent
)
20
{
21
Q_ASSERT(parent);
22
if
(!reply) {
23
setError(UnknownError, QStringLiteral(
"Null reply"
));
24
return
;
25
}
26
27
connect
(reply, &QNetworkReply::finished,
this
, &QPlaceSearchSuggestionReplyMapbox::onReplyFinished);
28
connect
(reply, &QNetworkReply::errorOccurred,
this
, &QPlaceSearchSuggestionReplyMapbox::onNetworkError);
29
30
connect
(
this
, &QPlaceReply::aborted, reply, &QNetworkReply::abort);
31
connect
(
this
, &QObject::destroyed, reply, &QObject::deleteLater);
32
}
33
34
QPlaceSearchSuggestionReplyMapbox
::~
QPlaceSearchSuggestionReplyMapbox
()
35
{
36
}
37
38
void
QPlaceSearchSuggestionReplyMapbox
::setError(QPlaceReply::Error errorCode,
const
QString &errorString)
39
{
40
QPlaceReply::setError(errorCode, errorString);
41
emit errorOccurred(errorCode, errorString);
42
43
setFinished(
true
);
44
emit
finished
();
45
}
46
47
void
QPlaceSearchSuggestionReplyMapbox
::onReplyFinished()
48
{
49
QNetworkReply *reply =
static_cast
<QNetworkReply *>(sender());
50
reply->deleteLater();
51
52
if
(reply->error() != QNetworkReply::NoError)
53
return
;
54
55
QJsonDocument document = QJsonDocument::fromJson(reply->readAll());
56
if
(!document.isObject()) {
57
setError(ParseError, tr(
"Response parse error"
));
58
return
;
59
}
60
61
const
QJsonArray features = document.object().value(QStringLiteral(
"features"
)).toArray();
62
63
QStringList suggestions;
64
for
(
const
QJsonValueConstRef feature : features) {
65
if
(feature.isObject())
66
suggestions.append(feature.toObject().value(QStringLiteral(
"text"
)).toString());
67
}
68
69
setSuggestions(suggestions);
70
71
setFinished(
true
);
72
emit
finished
();
73
}
74
75
void
QPlaceSearchSuggestionReplyMapbox
::onNetworkError(QNetworkReply::NetworkError error)
76
{
77
Q_UNUSED(error);
78
QNetworkReply *reply =
static_cast
<QNetworkReply *>(sender());
79
reply->deleteLater();
80
setError(CommunicationError, reply->errorString());
81
}
82
83
QT_END_NAMESPACE
QNetworkReply
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
Definition
qnetworkreply.h:30
QObjectData::parent
QObject * parent
Definition
qobject.h:74
QPlaceSearchSuggestionReplyMapbox
Definition
qplacesearchsuggestionreplymapbox.h:17
QPlaceSearchSuggestionReplyMapbox::~QPlaceSearchSuggestionReplyMapbox
~QPlaceSearchSuggestionReplyMapbox()
Definition
qplacesearchsuggestionreplymapbox.cpp:34
QSvgAbstractAnimation::finished
bool finished() const
Definition
qsvgabstractanimation.cpp:26
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
connect
connect(manager, &QNetworkAccessManager::finished, this, &MyClass::replyFinished)
qtlocation
src
plugins
geoservices
mapbox
qplacesearchsuggestionreplymapbox.cpp
Generated on
for Qt by
1.18.0