Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qgeocodereply_nokia.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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
7
8#include <QtPositioning/QGeoShape>
9#include <QtCore/QCoreApplication>
10
11Q_DECLARE_METATYPE(QList<QGeoLocation>)
12
13QT_BEGIN_NAMESPACE
14
15// manualBoundsRequired will be true if the parser has to manually
16// check if a given result lies within the viewport bounds,
17// and false if the bounds information was able to be supplied
18// to the server in the request (so it should not return any
19// out-of-bounds results).
20QGeoCodeReplyNokia::QGeoCodeReplyNokia(QNetworkReply *reply, int limit, int offset,
21 const QGeoShape &viewport, bool manualBoundsRequired,
22 QObject *parent)
23: QGeoCodeReply(parent), m_parsing(false), m_manualBoundsRequired(manualBoundsRequired)
24{
25 if (!reply) {
26 setError(UnknownError, QStringLiteral("Null reply"));
27 return;
28 }
29 qRegisterMetaType<QList<QGeoLocation> >();
30
31 connect(reply, &QNetworkReply::finished,
32 this, &QGeoCodeReplyNokia::networkFinished);
33 connect(reply, &QNetworkReply::errorOccurred,
34 this, &QGeoCodeReplyNokia::networkError);
35 connect(this, &QGeoCodeReply::aborted, reply, &QNetworkReply::abort);
36 connect(this, &QGeoCodeReply::aborted, [this](){ m_parsing = false; });
37 connect(this, &QObject::destroyed, reply, &QObject::deleteLater);
38
39
40 setLimit(limit);
41 setOffset(offset);
42 setViewport(viewport);
43}
44
45QGeoCodeReplyNokia::~QGeoCodeReplyNokia()
46{
47}
48
49void QGeoCodeReplyNokia::networkFinished()
50{
51 QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
52 reply->deleteLater();
53
54 if (reply->error() != QNetworkReply::NoError)
55 return;
56
57 QGeoCodeJsonParser *parser = new QGeoCodeJsonParser; // QRunnable, autoDelete = true.
58 if (m_manualBoundsRequired)
59 parser->setBounds(viewport());
60 connect(parser, &QGeoCodeJsonParser::results, this, &QGeoCodeReplyNokia::appendResults);
61 connect(parser, &QGeoCodeJsonParser::errorOccurred, this, &QGeoCodeReplyNokia::parseError);
62
63 m_parsing = true;
64 parser->parse(reply->readAll());
65}
66
67void QGeoCodeReplyNokia::networkError(QNetworkReply::NetworkError error)
68{
69 Q_UNUSED(error);
70
71 QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
72 reply->deleteLater();
73 setError(QGeoCodeReply::CommunicationError, reply->errorString());
74}
75
76void QGeoCodeReplyNokia::appendResults(const QList<QGeoLocation> &locations)
77{
78 if (!m_parsing)
79 return;
80
81 m_parsing = false;
82 setLocations(locations);
83 setFinished(true);
84}
85
86void QGeoCodeReplyNokia::parseError(const QString &errorString)
87{
88 Q_UNUSED(errorString);
89
90 setError(QGeoCodeReply::ParseError,
91 QCoreApplication::translate(NOKIA_PLUGIN_CONTEXT_NAME, RESPONSE_NOT_RECOGNIZABLE));
92}
93
94QT_END_NAMESPACE