File indexing completed on 2024-05-05 04:42:57

0001 /*
0002     SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef OSM_OVERPASSQUERY_H
0008 #define OSM_OVERPASSQUERY_H
0009 
0010 #include "datatypes.h"
0011 
0012 #include <QObject>
0013 #include <QRectF>
0014 
0015 class QNetworkReply;
0016 
0017 namespace OSM {
0018 
0019 /** An Overpass QL query job, to be executed by OverpassQueryManager.
0020  *  @note Use this wrongly can cause excessive load on Overpass servers,
0021  *  so only use this when you know what you are doing!
0022  */
0023 class OverpassQuery : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit OverpassQuery(QObject *parent = nullptr);
0028     ~OverpassQuery() override;
0029 
0030     /** Returns the raw (without bbox replacement) query string. */
0031     QString query() const;
0032     /** Returns the query with @p bbox applied. */
0033     QString query(const QRectF &bbox) const;
0034     /** Overpass QL query string.
0035      *  Can contain the '{{bbox}}' bounding box placeholder also supported by Overpass Turbo.
0036      */
0037     void setQuery(const QString &query);
0038 
0039     /** Bounding box for this query, values in degree. */
0040     QRectF boundingBox() const;
0041     /** Set the bounding box for this query, values in degree. */
0042     void setBoundingBox(const QRectF &bbox);
0043 
0044     /** Tile size in which the bounding box is broken down for querying.
0045      *  Values in degree.
0046      */
0047     QSizeF tileSize() const;
0048     /** Sets the tile size in which the bounding box is broken down for querying.
0049      *  Values in degree.
0050      */
0051     void setTileSize(const QSizeF &tileSize);
0052     /** Minimum tile size to which tiles can be broken down in case of query timeouts. */
0053     QSizeF minimumTileSize() const;
0054     /** Sets the minimum tile size.
0055      *  Should be smaller than tile size by a power of 2.
0056      */
0057     void setMinimumTileSize(const QSizeF &minTileSize);
0058 
0059     /** Error codes. */
0060     enum Error {
0061         NoError,
0062         QueryError, ///< generic query error
0063         QueryTimeout, ///< query exceeded its execution time budget
0064         NetworkError,
0065     };
0066     /** Error code of this query job. */
0067     Error error() const;
0068 
0069     /** Query result data set. */
0070     const DataSet& result() const;
0071     DataSet&& takeResult();
0072 
0073 Q_SIGNALS:
0074     void finished();
0075 
0076 private:
0077     friend class OverpassQueryManager;
0078     friend class OverpassQueryManagerPrivate;
0079 
0080     Error processReply(QNetworkReply *reply);
0081 
0082     QString m_query;
0083     QRectF m_bbox = { -180.0, -90.0, 360.0, 180.0 };
0084     QSizeF m_tileSize = { 360.0, 180.0 };
0085     QSizeF m_minimumTileSize = { 1.0, 1.0 };
0086     Error m_error = NoError;
0087     OSM::DataSet m_result;
0088 };
0089 
0090 }
0091 
0092 #endif // OSM_OVERPASSQUERY_H