swift
Loading...
Searching...
No Matches
vpilotmodelrule.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <Qt>
7
13
14using namespace swift::misc::aviation;
15using namespace swift::misc::simulation;
16
17SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation::fscommon, CVPilotModelRule)
18
19namespace swift::misc::simulation::fscommon
20{
21 CVPilotModelRule::CVPilotModelRule(const QString &modelName, const QString &folder, const QString &typeCode,
22 const QString &callsignPrefix, qint64 updated)
23 : ITimestampBased(updated), m_modelName(modelName.trimmed().toUpper()), m_folder(folder.trimmed().toUpper()),
24 m_typeCode(typeCode.trimmed().toUpper()), m_callsignPrefix(callsignPrefix.trimmed().toUpper()),
25 m_updatedMsSinceEpoch(updated)
26 {}
27
29 {
30 QString f(this->getFolder().toUpper().simplified());
31 f.replace(" ", "");
32 if (f.isEmpty()) return ("UNKNOWN");
33 if (f.startsWith("WOAI", Qt::CaseInsensitive))
34 {
35 return "WOAI";
36 }
37 if (f.startsWith("WORLDOFAI", Qt::CaseInsensitive))
38 {
39 return "WOAI";
40 }
41 if (f.startsWith("IVAO", Qt::CaseInsensitive))
42 {
43 return "IVAO";
44 }
45 if (f.startsWith("P3D", Qt::CaseInsensitive))
46 {
47 return "P3D";
48 }
49 if (f.startsWith("FSX", Qt::CaseInsensitive))
50 {
51 return "FSX";
52 }
53 if (f.startsWith("MYTRAFFIC", Qt::CaseInsensitive))
54 {
55 return "MYTRAFFIC";
56 }
57 if (f.startsWith("JUSTFLIGHT", Qt::CaseInsensitive))
58 {
59 return "JUSTFLIGHT";
60 }
61 if (f.startsWith("ULTIMATETRAFFIC", Qt::CaseInsensitive))
62 {
63 return "ULTIMATETRAFFIC";
64 }
65 if (f.startsWith("VIP", Qt::CaseInsensitive))
66 {
67 return "VIP";
68 }
69 return "??? - " + f;
70 }
71
73 {
74 if (index.isMyself())
75 {
76 return QVariant::fromValue(*this);
77 }
79 {
81 }
82 const auto i = index.frontCasted<ColumnIndex>();
83 switch (i)
84 {
85 case IndexModelName: return QVariant::fromValue(this->m_modelName);
86 case IndexFolder: return QVariant::fromValue(this->m_folder);
87 case IndexTypeCode: return QVariant::fromValue(this->m_typeCode);
88 case IndexCallsignPrefix: return QVariant::fromValue(this->m_callsignPrefix);
89 default: return CValueObject::propertyByIndex(index);
90 }
91 }
92
94 {
95 if (index.isMyself())
96 {
97 (*this) = variant.value<CVPilotModelRule>();
98 return;
99 }
101 {
103 return;
104 }
105 const auto i = index.frontCasted<ColumnIndex>();
106 switch (i)
107 {
108 case IndexModelName: this->setModelName(variant.value<QString>()); break;
109 case IndexFolder: this->setFolder(variant.value<QString>()); break;
110 case IndexTypeCode: this->setTypeCode(variant.value<QString>()); break;
111 case IndexCallsignPrefix: this->setCallsignPrefix(variant.value<QString>()); break;
112 default: CValueObject::setPropertyByIndex(index, variant); break;
113 }
114 }
115
117 {
118 Q_UNUSED(i18n);
119 QString s(this->m_modelName);
120 return s;
121 }
122
124 {
125 QString al(m_callsignPrefix);
126 if (al.length() > 3)
127 {
128 // some known hardcoded fixes
129 if (al.startsWith("USAF"))
130 {
131 al = "AIO";
132 }
133 }
134 const QString liveryPseudoCode(al.length() != 3 ? "" : al + "." + CLivery::standardLiveryMarker());
135 const CAircraftIcaoCode aircraftIcao(m_typeCode);
136 const CAirlineIcaoCode airlineIcao(al);
137 const CLivery livery(liveryPseudoCode, airlineIcao, "vPilot rule based");
138 const CDistributor distributor(getDistributor(), "vPilot based", "", "");
140 aircraftIcao, livery);
141 const CSimulatorInfo sim(CSimulatorInfo::P3D);
143 model.setDistributor(distributor);
144 model.setSimulator(sim);
145 return model;
146 }
147
148} // namespace swift::misc::simulation::fscommon
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.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
ITimestampBased()=default
Constructor.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
qint64 m_timestampMSecsSinceEpoch
timestamp value
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void setMSecsSinceEpoch(qint64 mSecsSinceEpoch)
Timestamp as ms value.
Value object for ICAO classification.
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Definition livery.h:29
static const QString & standardLiveryMarker()
Standard livery marker string.
Definition livery.cpp:327
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
Aircraft model (used by another pilot, my models on disk).
@ TypeVPilotRuleBased
based on a vPilot rule
void setSimulator(const CSimulatorInfo &simulator)
Set simulator info.
void setDistributor(const CDistributor &distributor)
Set distributor.
static const QString & autoGenerated()
Hint, that model was automatically generated (e.g. by auto stashing).
Value object encapsulating information of software distributor.
Definition distributor.h:33
Simple hardcoded info about the corresponding simulator.
QString getDistributor() const
Distributor derived from folder (hardcoded).
void setModelName(const QString &name)
Model name.
void setTypeCode(const QString &code)
Type code.
CVPilotModelRule()=default
Default constructor.
QString convertToQString(bool i18n=false) const
Cast as QString.
void setCallsignPrefix(const QString &callsign)
Callsign prefix.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
void setFolder(const QString &folder)
Folder.
const QString & getFolder() const
Get folder.
CAircraftModel toAircraftModel() const
Convert into aircraft model.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isEmpty() const const
qsizetype length() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
CaseInsensitive
QVariant fromValue(T &&value)
T value() const &const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition valueobject.h:67