KWeatherCore

locationqueryresult.cpp
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#include "locationqueryresult.h"
8
9#include <KCountry>
10
11#include <memory>
12#include <optional>
13
14namespace KWeatherCore
15{
16class LocationQueryResult::LocationQueryResultPrivate
17{
18public:
19 double latitude, longitude;
20 QString toponymName, name, countryCode, geonameId;
21 std::optional<QString> subdivision;
22};
23LocationQueryResult::LocationQueryResult()
24 : d(std::make_unique<LocationQueryResultPrivate>())
25{
26}
27LocationQueryResult::LocationQueryResult(LocationQueryResult &&other) noexcept = default;
28LocationQueryResult::LocationQueryResult(double latitude,
29 double longitude,
30 QString toponymName,
31 QString name,
32 QString countryCode,
33 QString geonameId,
34 std::optional<QString> subdivision)
35 : d(std::make_unique<LocationQueryResultPrivate>())
36{
37 d->latitude = latitude;
38 d->longitude = longitude;
39 d->toponymName = std::move(toponymName);
40 d->name = std::move(name);
41 d->countryCode = std::move(countryCode);
42 d->geonameId = std::move(geonameId);
43 d->subdivision = std::move(subdivision);
44}
45LocationQueryResult::LocationQueryResult(const LocationQueryResult &other)
46 : d(std::make_unique<LocationQueryResultPrivate>())
47{
48 *d = *other.d;
49}
50LocationQueryResult::~LocationQueryResult() = default;
51LocationQueryResult &LocationQueryResult::operator=(const LocationQueryResult &other)
52{
53 *d = *other.d;
54 return *this;
55}
56LocationQueryResult &LocationQueryResult::operator=(LocationQueryResult &&other) noexcept = default;
57double LocationQueryResult::latitude() const
58{
59 return d->latitude;
60}
61double LocationQueryResult::longitude() const
62{
63 return d->longitude;
64}
65const QString &LocationQueryResult::toponymName() const
66{
67 return d->toponymName;
68}
69const QString &LocationQueryResult::name() const
70{
71 return d->name;
72}
73const QString &LocationQueryResult::countryCode() const
74{
75 return d->countryCode;
76}
77QString LocationQueryResult::countryName() const
78{
79 return KCountry::fromAlpha2(d->countryCode).name();
80}
81const QString &LocationQueryResult::geonameId() const
82{
83 return d->geonameId;
84}
85const std::optional<QString> &LocationQueryResult::subdivision() const
86{
87 return d->subdivision;
88}
89}
90
91#include "moc_locationqueryresult.cpp"
static KCountry fromAlpha2(const char *alpha2Code)
QString name() const
Class represents location query result.
const std::optional< QString > & subdivision() const
Country subdivision such as state, province, etc.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:02:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.