File indexing completed on 2024-05-05 16:49:22
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 class QNetworkReply; 0013 namespace KWeatherCore 0014 { 0015 class LocationQueryPrivate; 0016 /** 0017 * @short Class locates current location and search locations by name 0018 * 0019 * This is a class that locates current location (GPS or IP) and search 0020 * locations by name 0021 * ## Usage example 0022 * 0023 * Example usage: 0024 * @code 0025 * #include <KWeatherCore/LocationQuery> 0026 * using namespace KWeatherCore; 0027 * 0028 * //... 0029 * 0030 * LocationQuery m_locationSource; 0031 * 0032 * // find places called "Oslo" 0033 * m_locationSource.query("Oslo") 0034 * connect(m_locationSource, &LocationQuery::queryFinished, 0035 * [](const std::vector<LocationQueryResult> &result) 0036 * { 0037 * for(auto location : result) 0038 * { 0039 * qDebug() << location.toponymName(); 0040 * } 0041 * }); 0042 * connect(m_locationSource, &LocationQuery::queryError, 0043 * []{qDebug() << "can't find this place";}); 0044 * 0045 * m_locationSource.locate(); 0046 * connect(m_locationSource, &LocationQuery::located, 0047 * [](const LocationQueryResult &result){qDebug() << "your coordinate: " << 0048 * result.latitude() << ", " << longitude();} 0049 * //... 0050 * @endcode 0051 * 0052 * @author Han Young <hanyoung@protonmail.com> 0053 */ 0054 class KWEATHERCORE_EXPORT LocationQuery : public QObject 0055 { 0056 Q_OBJECT 0057 public: 0058 /** 0059 * LocationQuery 0060 */ 0061 LocationQuery(QObject *parent = nullptr); 0062 /** 0063 * query query locations by name 0064 * @param name name of location, not necessary in English 0065 * @param number max numbers of query returned, the actual size could be 0066 * less than @param number 0067 */ 0068 void query(QString name, int number = 30); 0069 /** 0070 * locate current location 0071 */ 0072 void locate(); 0073 Q_SIGNALS: 0074 /** 0075 * the name search has completed 0076 */ 0077 void queryFinished(std::vector<LocationQueryResult> result); 0078 /** 0079 * current location has been determined 0080 */ 0081 void located(const LocationQueryResult &result); 0082 /** 0083 * a error has encounted during query, network error or no result 0084 * found 0085 */ 0086 void queryError(); 0087 0088 private: 0089 LocationQueryPrivate *d = nullptr; 0090 }; 0091 }