swift
Loading...
Searching...
No Matches
simbriefdata.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QStringBuilder>
7
9
10using namespace swift::misc::network;
11
12SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::aviation, CSimBriefData)
13
14namespace swift::misc::aviation
15{
17 {
18 static const QStringList cats { CLogCategories::flightPlan() };
19 return cats;
20 }
21
22 CSimBriefData::CSimBriefData() : m_url("https://www.simbrief.com/api/xml.fetcher.php") {}
23
24 CSimBriefData::CSimBriefData(const QString &url, const QString &username) : m_url(url), m_username(username) {}
25
27 {
28 CUrl url(this->getUrl());
29 if (!m_username.isEmpty())
30 {
31 url.setQuery("username=" % m_username);
32 }
33 return url;
34 }
35
37 {
38 if (index.isMyself())
39 {
40 return QVariant::fromValue(*this);
41 }
42 const auto i = index.frontCasted<ColumnIndex>();
43 switch (i)
44 {
45 case IndexUrl: return QVariant::fromValue(m_url);
46 case IndexUsername: return QVariant::fromValue(m_username);
47 default: return CValueObject::propertyByIndex(index);
48 }
49 }
50
52 {
53 if (index.isMyself())
54 {
55 (*this) = variant.value<CSimBriefData>();
56 return;
57 }
58 const auto i = index.frontCasted<ColumnIndex>();
59 switch (i)
60 {
61 case IndexUrl: m_url = variant.toString(); break;
62 case IndexUsername: m_username = variant.toString(); break;
63 default: CValueObject::setPropertyByIndex(index, variant); break;
64 }
65 }
66
68 {
69 Q_UNUSED(i18n);
70 return m_username % " " % m_url;
71 }
72} // namespace swift::misc::aviation
static const QString & flightPlan()
Flight plan.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
network::CUrl getUrlAndUsername() const
Get URL plus username.
QString convertToQString(bool i18n=false) const
Cast as QString.
const QString & getUrl() const
Get URL.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
static const QStringList & getLogCategories()
The log. catgeories.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition mixinindex.h:167
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition mixinindex.h:180
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
Definition url.h:27
void setQuery(const QString &query)
Set query.
Definition url.cpp:67
QVariant fromValue(T &&value)
QString toString() const const
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67