KOSMIndoorMap

overpassquery.cpp
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "overpassquery.h"
8#include "io.h"
9
10#include <QNetworkReply>
11
12using namespace OSM;
13
14OverpassQuery::OverpassQuery(QObject* parent)
15 : QObject(parent)
16{
17}
18
19OverpassQuery::~OverpassQuery() = default;
20
22{
23 return m_query;
24}
25
27{
28 const QString bboxStr = QString::number(bbox.y()) + QLatin1Char(',') + QString::number(bbox.x()) + QLatin1Char(',') + QString::number(bbox.y() + bbox.height()) + QLatin1Char(',') + QString::number(bbox.x() + bbox.width());
29 auto q = m_query;
30 return q.replace(QLatin1String("{{bbox}}"), bboxStr);
31}
32
34{
35 m_query = query;
36}
37
39{
40 return m_bbox;
41}
42
44{
45 m_bbox = bbox;
46}
47
49{
50 return m_tileSize;
51}
52
54{
55 m_tileSize = tileSize;
56}
57
59{
60 return m_minimumTileSize;
61}
62
64{
65 m_minimumTileSize = minTileSize;
66}
67
69{
70 return m_error;
71}
72
74{
75 return m_result;
76}
77
78DataSet&& OverpassQuery::takeResult()
79{
80 return std::move(m_result);
81}
82
83OverpassQuery::Error OverpassQuery::processReply(QNetworkReply *reply)
84{
85 auto reader = OSM::IO::readerForMimeType(u"application/vnd.openstreetmap.data+xml", &m_result);
86 if (!reader) {
87 qWarning() << "No support for reading OSM XML available!";
88 return QueryError;
89 }
90 reader->read(reply);
91 if (!reader->errorString().isEmpty()) {
92 qWarning() << "Query error:" << reader->errorString();
93 qWarning() << "Request:" << reply->request().url();
95 }
96 qDebug() << "Nodes:" << m_result.nodes.size();
97 qDebug() << "Ways:" << m_result.ways.size();
98 qDebug() << "Relations:" << m_result.relations.size();
99 return NoError;
100}
101
102#include "moc_overpassquery.cpp"
A set of nodes, ways and relations.
Definition datatypes.h:346
@ QueryTimeout
query exceeded its execution time budget
@ QueryError
generic query error
QString query() const
Returns the raw (without bbox replacement) query string.
QSizeF minimumTileSize() const
Minimum tile size to which tiles can be broken down in case of query timeouts.
Error error() const
Error code of this query job.
void setTileSize(const QSizeF &tileSize)
Sets the tile size in which the bounding box is broken down for querying.
QSizeF tileSize() const
Tile size in which the bounding box is broken down for querying.
QRectF boundingBox() const
Bounding box for this query, values in degree.
void setMinimumTileSize(const QSizeF &minTileSize)
Sets the minimum tile size.
const DataSet & result() const
Query result data set.
void setQuery(const QString &query)
Overpass QL query string.
void setBoundingBox(const QRectF &bbox)
Set the bounding box for this query, values in degree.
KOSM_EXPORT std::unique_ptr< AbstractReader > readerForMimeType(QStringView mimeType, OSM::DataSet *dataSet)
Returns a suitable reader for the given MIME type.
Definition io.cpp:51
Low-level types and functions to work with raw OSM data as efficiently as possible.
QNetworkRequest request() const const
QUrl url() const const
qreal height() const const
qreal width() const const
qreal x() const const
qreal y() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
QString number(double n, char format, int precision)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
CaseInsensitive
QString errorString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:55:43 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.