swift
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 
10 #include "misc/aviation/livery.h"
13 
14 using namespace swift::misc::aviation;
15 using namespace swift::misc::simulation;
16 
17 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation::fscommon, CVPilotModelRule)
18 
19 namespace 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)) { return "WOAI"; }
34  if (f.startsWith("WORLDOFAI", Qt::CaseInsensitive)) { return "WOAI"; }
35  if (f.startsWith("IVAO", Qt::CaseInsensitive)) { return "IVAO"; }
36  if (f.startsWith("P3D", Qt::CaseInsensitive)) { return "P3D"; }
37  if (f.startsWith("FSX", Qt::CaseInsensitive)) { return "FSX"; }
38  if (f.startsWith("MYTRAFFIC", Qt::CaseInsensitive)) { return "MYTRAFFIC"; }
39  if (f.startsWith("JUSTFLIGHT", Qt::CaseInsensitive)) { return "JUSTFLIGHT"; }
40  if (f.startsWith("ULTIMATETRAFFIC", Qt::CaseInsensitive)) { return "ULTIMATETRAFFIC"; }
41  if (f.startsWith("VIP", Qt::CaseInsensitive)) { return "VIP"; }
42  return "??? - " + f;
43  }
44 
46  {
47  if (index.isMyself()) { return QVariant::fromValue(*this); }
49  const auto i = index.frontCasted<ColumnIndex>();
50  switch (i)
51  {
52  case IndexModelName: return QVariant::fromValue(this->m_modelName);
53  case IndexFolder: return QVariant::fromValue(this->m_folder);
54  case IndexTypeCode: return QVariant::fromValue(this->m_typeCode);
55  case IndexCallsignPrefix: return QVariant::fromValue(this->m_callsignPrefix);
56  default: return CValueObject::propertyByIndex(index);
57  }
58  }
59 
61  {
62  if (index.isMyself())
63  {
64  (*this) = variant.value<CVPilotModelRule>();
65  return;
66  }
68  {
70  return;
71  }
72  const auto i = index.frontCasted<ColumnIndex>();
73  switch (i)
74  {
75  case IndexModelName: this->setModelName(variant.value<QString>()); break;
76  case IndexFolder: this->setFolder(variant.value<QString>()); break;
77  case IndexTypeCode: this->setTypeCode(variant.value<QString>()); break;
78  case IndexCallsignPrefix: this->setCallsignPrefix(variant.value<QString>()); break;
79  default: CValueObject::setPropertyByIndex(index, variant); break;
80  }
81  }
82 
84  {
85  Q_UNUSED(i18n);
86  QString s(this->m_modelName);
87  return s;
88  }
89 
91  {
92  QString al(m_callsignPrefix);
93  if (al.length() > 3)
94  {
95  // some known hardcoded fixes
96  if (al.startsWith("USAF")) { al = "AIO"; }
97  }
98  const QString liveryPseudoCode(al.length() != 3 ? "" : al + "." + CLivery::standardLiveryMarker());
99  const CAircraftIcaoCode aircraftIcao(m_typeCode);
100  const CAirlineIcaoCode airlineIcao(al);
101  const CLivery livery(liveryPseudoCode, airlineIcao, "vPilot rule based");
102  const CDistributor distributor(getDistributor(), "vPilot based", "", "");
104  aircraftIcao, livery);
105  const CSimulatorInfo sim(CSimulatorInfo::FSX_P3D);
107  model.setDistributor(distributor);
108  model.setSimulator(sim);
109  return model;
110  }
111 
112 } // 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.
Entity with timestamp.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
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
ColumnIndex
Base class enums.
Definition: mixinindex.h:44
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
Definition: mixinindex.h:158
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:165
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
@ TypeVPilotRuleBased
based on a vPilot rule
Definition: aircraftmodel.h:85
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.
Definition: simulatorinfo.h:41
Value object encapsulating information of software distributor.
QString getDistributor() const
Distributor derived from folder (hardcoded)
void setModelName(const QString &name)
Model name.
void setTypeCode(const QString &code)
Type code.
const QString & getFolder() const
Get folder.
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.
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