KWeatherCore

locationquery.h
1/*
2 * SPDX-FileCopyrightText: 2020-2021 Han Young <hanyoung@protonmail.com>
3 * SPDX-FileCopyrightText: 2020 Devin Lin <espidev@gmail.com>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7
8#pragma once
9#include "locationqueryresult.h"
10#include <QObject>
11#include <kweathercore/kweathercore_export.h>
12#include <memory>
13
15
16namespace KWeatherCore
17{
18class LocationQueryReply;
19class LocationQueryPrivate;
20/**
21 * @short Class locates current location and search locations by name
22 *
23 * This is a class that locates current location (GPS or IP) and search
24 * locations by name
25 * ## Usage example
26 *
27 * Example usage:
28 * @code
29 * #include <KWeatherCore/LocationQuery>
30 * using namespace KWeatherCore;
31 *
32 * //...
33 *
34 * LocationQuery m_locationSource;
35 *
36 * // find places called "Oslo"
37 * auto reply = m_locationSource.query("Oslo")
38 * connect(reply, &LocationQueryReply::finished, []()
39 * {
40 * reply->deleteLater();
41 * if (reply != LocationQueryReply::NoError) {
42 * qDebug() << "can't find this place";
43 * return;
44 * }
45 * for(auto location : reply->result())
46 * {
47 * qDebug() << location.toponymName();
48 * }
49 * });
50 *
51 * auto reply = m_locationSource.locate();
52 * connect(reply, &LocationQuery::finsihed, []() {
53 * reply->deleteLater();
54 * if (reply->error() == LocationQueryReply::NoError)
55 * qDebug() << "your coordinate: " << reply->result.first().latitude() << ", " << reply->result().first().replylongitude();
56 * }
57 * //...
58 * @endcode
59 *
60 * @author Han Young <hanyoung@protonmail.com>
61 */
62class KWEATHERCORE_EXPORT LocationQuery : public QObject
63{
64 Q_OBJECT
65public:
66 /**
67 * LocationQuery
68 */
69 explicit LocationQuery(QObject *parent = nullptr);
70 ~LocationQuery() override;
71 /**
72 * query query locations by name
73 * @param name name of location, not necessary in English
74 * @param number max numbers of query returned, the actual size could be
75 * less than @param number
76 */
77 LocationQueryReply *query(const QString &name, int number = 30);
78 /**
79 * locate current location
80 */
81 LocationQueryReply *locate();
82
83 /** Set the network access manager to use for network operations.
84 * If not set, an instance is created internally.
85 * Ownership is not transferred.
86 */
87 void setNetworkAccessManager(QNetworkAccessManager *nam);
88
89private:
90 std::unique_ptr<LocationQueryPrivate> d;
91};
92}
Asynchronous reply for a location query.
Class locates current location and search locations by name.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.