File indexing completed on 2024-04-28 04:42:42
0001 /* 0002 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com> 0003 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com> 0004 * 0005 * SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 #include "locationqueryresult.h" 0010 #include <QObject> 0011 #include <kweathercore/kweathercore_export.h> 0012 #include <memory> 0013 0014 class QNetworkAccessManager; 0015 0016 namespace KWeatherCore 0017 { 0018 class LocationQueryReply; 0019 class LocationQueryPrivate; 0020 /** 0021 * @short Class locates current location and search locations by name 0022 * 0023 * This is a class that locates current location (GPS or IP) and search 0024 * locations by name 0025 * ## Usage example 0026 * 0027 * Example usage: 0028 * @code 0029 * #include <KWeatherCore/LocationQuery> 0030 * using namespace KWeatherCore; 0031 * 0032 * //... 0033 * 0034 * LocationQuery m_locationSource; 0035 * 0036 * // find places called "Oslo" 0037 * auto reply = m_locationSource.query("Oslo") 0038 * connect(reply, &LocationQueryReply::finished, []() 0039 * { 0040 * reply->deleteLater(); 0041 * if (reply != LocationQueryReply::NoError) { 0042 * qDebug() << "can't find this place"; 0043 * return; 0044 * } 0045 * for(auto location : reply->result()) 0046 * { 0047 * qDebug() << location.toponymName(); 0048 * } 0049 * }); 0050 * 0051 * auto reply = m_locationSource.locate(); 0052 * connect(reply, &LocationQuery::finsihed, []() { 0053 * reply->deleteLater(); 0054 * if (reply->error() == LocationQueryReply::NoError) 0055 * qDebug() << "your coordinate: " << reply->result.first().latitude() << ", " << reply->result().first().replylongitude(); 0056 * } 0057 * //... 0058 * @endcode 0059 * 0060 * @author Han Young <hanyoung@protonmail.com> 0061 */ 0062 class KWEATHERCORE_EXPORT LocationQuery : public QObject 0063 { 0064 Q_OBJECT 0065 public: 0066 /** 0067 * LocationQuery 0068 */ 0069 explicit LocationQuery(QObject *parent = nullptr); 0070 ~LocationQuery() override; 0071 /** 0072 * query query locations by name 0073 * @param name name of location, not necessary in English 0074 * @param number max numbers of query returned, the actual size could be 0075 * less than @param number 0076 */ 0077 LocationQueryReply *query(const QString &name, int number = 30); 0078 /** 0079 * locate current location 0080 */ 0081 LocationQueryReply *locate(); 0082 0083 /** Set the network access manager to use for network operations. 0084 * If not set, an instance is created internally. 0085 * Ownership is not transferred. 0086 */ 0087 void setNetworkAccessManager(QNetworkAccessManager *nam); 0088 0089 private: 0090 std::unique_ptr<LocationQueryPrivate> d; 0091 }; 0092 }