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() {}
22 
23  CVPilotModelRule::CVPilotModelRule(const QString &modelName, const QString &folder, const QString &typeCode,
24  const QString &callsignPrefix, qint64 updated)
25  : ITimestampBased(updated), m_modelName(modelName.trimmed().toUpper()), m_folder(folder.trimmed().toUpper()),
26  m_typeCode(typeCode.trimmed().toUpper()), m_callsignPrefix(callsignPrefix.trimmed().toUpper()),
27  m_updatedMsSinceEpoch(updated)
28  {}
29 
31  {
32  QString f(this->getFolder().toUpper().simplified());
33  f.replace(" ", "");
34  if (f.isEmpty()) return ("UNKNOWN");
35  if (f.startsWith("WOAI", Qt::CaseInsensitive)) { return "WOAI"; }
36  if (f.startsWith("WORLDOFAI", Qt::CaseInsensitive)) { return "WOAI"; }
37  if (f.startsWith("IVAO", Qt::CaseInsensitive)) { return "IVAO"; }
38  if (f.startsWith("P3D", Qt::CaseInsensitive)) { return "P3D"; }
39  if (f.startsWith("FSX", Qt::CaseInsensitive)) { return "FSX"; }
40  if (f.startsWith("MYTRAFFIC", Qt::CaseInsensitive)) { return "MYTRAFFIC"; }
41  if (f.startsWith("JUSTFLIGHT", Qt::CaseInsensitive)) { return "JUSTFLIGHT"; }
42  if (f.startsWith("ULTIMATETRAFFIC", Qt::CaseInsensitive)) { return "ULTIMATETRAFFIC"; }
43  if (f.startsWith("VIP", Qt::CaseInsensitive)) { return "VIP"; }
44  return "??? - " + f;
45  }
46 
48  {
49  if (index.isMyself()) { return QVariant::fromValue(*this); }
51  ColumnIndex i = index.frontCasted<ColumnIndex>();
52  switch (i)
53  {
54  case IndexModelName: return QVariant::fromValue(this->m_modelName);
55  case IndexFolder: return QVariant::fromValue(this->m_folder);
56  case IndexTypeCode: return QVariant::fromValue(this->m_typeCode);
57  case IndexCallsignPrefix: return QVariant::fromValue(this->m_callsignPrefix);
58  default: return CValueObject::propertyByIndex(index);
59  }
60  }
61 
62  void CVPilotModelRule::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
63  {
64  if (index.isMyself())
65  {
66  (*this) = variant.value<CVPilotModelRule>();
67  return;
68  }
70  {
72  return;
73  }
74  ColumnIndex i = index.frontCasted<ColumnIndex>();
75  switch (i)
76  {
77  case IndexModelName: this->setModelName(variant.value<QString>()); break;
78  case IndexFolder: this->setFolder(variant.value<QString>()); break;
79  case IndexTypeCode: this->setTypeCode(variant.value<QString>()); break;
80  case IndexCallsignPrefix: this->setCallsignPrefix(variant.value<QString>()); break;
81  default: CValueObject::setPropertyByIndex(index, variant); break;
82  }
83  }
84 
85  QString CVPilotModelRule::convertToQString(bool i18n) const
86  {
87  Q_UNUSED(i18n);
88  QString s(this->m_modelName);
89  return s;
90  }
91 
93  {
94  QString al(m_callsignPrefix);
95  if (al.length() > 3)
96  {
97  // some known hardcoded fixes
98  if (al.startsWith("USAF")) { al = "AIO"; }
99  }
100  const QString liveryPseudoCode(al.length() != 3 ? "" : al + "." + CLivery::standardLiveryMarker());
101  const CAircraftIcaoCode aircraftIcao(m_typeCode);
102  const CAirlineIcaoCode airlineIcao(al);
103  const CLivery livery(liveryPseudoCode, airlineIcao, "vPilot rule based");
104  const CDistributor distributor(getDistributor(), "vPilot based", "", "");
106  aircraftIcao, livery);
107  const CSimulatorInfo sim(CSimulatorInfo::FSX_P3D);
109  model.setDistributor(distributor);
110  model.setSimulator(sim);
111  return model;
112  }
113 
114 } // 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:160
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Definition: mixinindex.h:167
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.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67