swift
Loading...
Searching...
No Matches
ecosystem.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
7#include "misc/iconlist.h"
8#include "misc/verify.h"
9
10SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::network, CEcosystem)
11
12namespace swift::misc::network
13{
15 {
16 Q_UNUSED(i18n);
17 return this->getSystemString();
18 }
19
21 {
22 static const CEcosystem e(Unspecified);
23 return e;
24 }
25
27 {
28 static const CEcosystem e(VATSIM);
29 return e;
30 }
31
33 {
34 static const CEcosystem e(PrivateFSD);
35 return e;
36 }
37
39 {
40 static const QString u("unknown");
41 static const QString v("VATSIM");
42 static const QString fsd("FSD");
43 static const QString no("no system");
44
45 switch (this->getSystem())
46 {
47 case VATSIM: return v;
48 case PrivateFSD: return fsd;
49 case NoSystem: return no;
50 case Unspecified:
51 default: return u;
52 }
53 }
54
56 {
57 if (index.isMyself())
58 {
59 return QVariant::fromValue(*this);
60 }
61 const auto i = index.frontCasted<ColumnIndex>();
62 switch (i)
63 {
64 case IndexSystem: return QVariant::fromValue(m_system);
65 case IndexSystemString: return QVariant::fromValue(this->getSystemString());
66 default: return CValueObject::propertyByIndex(index);
67 }
68 }
69
71 {
72 if (index.isMyself())
73 {
74 (*this) = variant.value<CEcosystem>();
75 return;
76 }
77 const auto i = index.frontCasted<ColumnIndex>();
78 switch (i)
79 {
80 case IndexSystem: m_system = variant.toInt(); break;
81 default: CValueObject::setPropertyByIndex(index, variant); break;
82 }
83 }
84
86 {
87 if (index.isMyself())
88 {
89 return Compare::compare(m_system, compareValue.m_system);
90 }
91 const auto i = index.frontCasted<ColumnIndex>();
92 switch (i)
93 {
94 case IndexSystem: return Compare::compare(m_system, compareValue.m_system);
95 default: break;
96 }
97 SWIFT_VERIFY_X(false, Q_FUNC_INFO, qUtf8Printable("No comparison for index " + index.toQString()));
98 return 0;
99 }
100} // namespace swift::misc::network
Non-owning reference to a CPropertyIndex with a subset of its features.
QString toQString(bool i18n=false) const
Cast as QString.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
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
CEcosystem()=default
Default constructor.
@ NoSystem
no relevant ecosystem
Definition ecosystem.h:34
@ PrivateFSD
Private FSD environment.
Definition ecosystem.h:36
int comparePropertyByIndex(CPropertyIndexRef index, const CEcosystem &compareValue) const
Compare for index.
Definition ecosystem.cpp:85
static const CEcosystem & vatsim()
VATSIM eco system.
Definition ecosystem.cpp:26
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition ecosystem.cpp:70
System getSystem() const
Get system.
Definition ecosystem.h:46
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
Definition ecosystem.cpp:55
static const CEcosystem & privateFsd()
FSD private.
Definition ecosystem.cpp:32
static const CEcosystem & unspecified()
Unspecified.
Definition ecosystem.cpp:20
ColumnIndex
Properties by index.
Definition ecosystem.h:25
QString convertToQString(bool i18n=false) const
Cast as QString.
Definition ecosystem.cpp:14
const QString & getSystemString() const
Get the system string.
Definition ecosystem.cpp:38
int compare(T a, T b)
Compare arithmetic values.
QVariant fromValue(T &&value)
int toInt(bool *ok) 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
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.
Definition verify.h:26