1 /* 2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef OSM_OVERPASSQUERY_H 8 #define OSM_OVERPASSQUERY_H 9 10 #include "datatypes.h" 11 12 #include <QObject> 13 #include <QRectF> 14 15 class QNetworkReply; 16 17 namespace OSM { 18 19 /** An Overpass QL query job, to be executed by OverpassQueryManager. 20 * @note Use this wrongly can cause excessive load on Overpass servers, 21 * so only use this when you know what you are doing! 22 */ 23 class OverpassQuery : public QObject 24 { 25 Q_OBJECT 26 public: 27 explicit OverpassQuery(QObject *parent = nullptr); 28 ~OverpassQuery() override; 29 30 /** Returns the raw (without bbox replacement) query string. */ 31 QString query() const; 32 /** Returns the query with @p bbox applied. */ 33 QString query(const QRectF &bbox) const; 34 /** Overpass QL query string. 35 * Can contain the '{{bbox}}' bounding box placeholder also supported by Overpass Turbo. 36 */ 37 void setQuery(const QString &query); 38 39 /** Bounding box for this query, values in degree. */ 40 QRectF boundingBox() const; 41 /** Set the bounding box for this query, values in degree. */ 42 void setBoundingBox(const QRectF &bbox); 43 44 /** Tile size in which the bounding box is broken down for querying. 45 * Values in degree. 46 */ 47 QSizeF tileSize() const; 48 /** Sets the tile size in which the bounding box is broken down for querying. 49 * Values in degree. 50 */ 51 void setTileSize(const QSizeF &tileSize); 52 /** Minimum tile size to which tiles can be broken down in case of query timeouts. */ 53 QSizeF minimumTileSize() const; 54 /** Sets the minimum tile size. 55 * Should be smaller than tile size by a power of 2. 56 */ 57 void setMinimumTileSize(const QSizeF &minTileSize); 58 59 /** Error codes. */ 60 enum Error { 61 NoError, 62 QueryError, ///< generic query error 63 QueryTimeout, ///< query exceeded its execution time budget 64 NetworkError, 65 }; 66 /** Error code of this query job. */ 67 Error error() const; 68 69 /** Query result data set. */ 70 const DataSet& result() const; 71 DataSet&& takeResult(); 72 73 Q_SIGNALS: 74 void finished(); 75 76 private: 77 friend class OverpassQueryManager; 78 friend class OverpassQueryManagerPrivate; 79 80 Error processReply(QNetworkReply *reply); 81 82 QString m_query; 83 QRectF m_bbox = { -180.0, -90.0, 360.0, 180.0 }; 84 QSizeF m_tileSize = { 360.0, 180.0 }; 85 QSizeF m_minimumTileSize = { 1.0, 1.0 }; 86 Error m_error = NoError; 87 OSM::DataSet m_result; 88 }; 89 90 } 91 92 #endif // OSM_OVERPASSQUERY_H 93