KOSMIndoorMap

overpassquery.cpp
1 /*
2  SPDX-FileCopyrightText: 2020 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "overpassquery.h"
8 #include "xmlparser.h"
9 
10 #include <QNetworkReply>
11 
12 using namespace OSM;
13 
14 OverpassQuery::OverpassQuery(QObject* parent)
15  : QObject(parent)
16 {
17 }
18 
19 OverpassQuery::~OverpassQuery() = default;
20 
21 QString OverpassQuery::query() const
22 {
23  return m_query;
24 }
25 
26 QString OverpassQuery::query(const QRectF &bbox) const
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 
33 void OverpassQuery::setQuery(const QString &query)
34 {
35  m_query = query;
36 }
37 
38 QRectF OverpassQuery::boundingBox() const
39 {
40  return m_bbox;
41 }
42 
43 void OverpassQuery::setBoundingBox(const QRectF &bbox)
44 {
45  m_bbox = bbox;
46 }
47 
48 QSizeF OverpassQuery::tileSize() const
49 {
50  return m_tileSize;
51 }
52 
53 void OverpassQuery::setTileSize(const QSizeF &tileSize)
54 {
55  m_tileSize = tileSize;
56 }
57 
58 QSizeF OverpassQuery::minimumTileSize() const
59 {
60  return m_minimumTileSize;
61 }
62 
63 void OverpassQuery::setMinimumTileSize(const QSizeF &minTileSize)
64 {
65  m_minimumTileSize = minTileSize;
66 }
67 
68 OverpassQuery::Error OverpassQuery::error() const
69 {
70  return m_error;
71 }
72 
73 const DataSet& OverpassQuery::result() const
74 {
75  return m_result;
76 }
77 
78 DataSet&& OverpassQuery::takeResult()
79 {
80  return std::move(m_result);
81 }
82 
83 OverpassQuery::Error OverpassQuery::processReply(QNetworkReply *reply)
84 {
85  XmlParser p(&m_result);
86  p.parse(reply);
87  if (!p.error().isEmpty()) {
88  qWarning() << "Query error:" << p.error();
89  qWarning() << "Request:" << reply->request().url();
90  return p.error().contains(QLatin1String("timed out"), Qt::CaseInsensitive) ? QueryTimeout : QueryError;
91  }
92  qDebug() << "Nodes:" << m_result.nodes.size();
93  qDebug() << "Ways:" << m_result.ways.size();
94  qDebug() << "Relations:" << m_result.relations.size();
95  return NoError;
96 }
Error
Error codes.
Definition: overpassquery.h:62
qreal x() const const
qreal y() const const
QNetworkRequest request() const const
QString number(int n, int base)
CaseInsensitive
QUrl url() const const
QString & replace(int position, int n, QChar after)
qreal width() const const
A set of nodes, ways and relations.
Definition: datatypes.h:283
qreal height() const const
Low-level types and functions to work with raw OSM data as efficiently as possible.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 23:04:00 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.