swift
distributorlistpreferences.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QtGlobal>
7 
8 SWIFT_DEFINE_VALUEOBJECT_MIXINS(swift::misc::simulation, CDistributorListPreferences)
9 
10 namespace swift::misc::simulation
11 {
13 
15  {
16  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
17  switch (simulator.getSimulator())
18  {
19  case CSimulatorInfo::FSX: return m_distributorsFsx;
20  case CSimulatorInfo::P3D: return m_distributorsP3d;
21  case CSimulatorInfo::FS9: return m_distributorsFs9;
22  case CSimulatorInfo::FG: return m_distributorsFG;
23  case CSimulatorInfo::XPLANE: return m_distributorsXPlane;
24  case CSimulatorInfo::MSFS: return m_distributorsMsfs;
25  case CSimulatorInfo::MSFS2024: return m_distributorsMsfs2024;
26  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
27  }
28 
29  static const CDistributorList empty;
30  return empty;
31  }
32 
34  {
35  return this->getDistributors(simulator).frontOrDefault();
36  }
37 
39  const CSimulatorInfo &simulator)
40  {
41  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
42  CDistributorList d(distributors);
43  d.sortAscendingByOrder(); // make sure we are sorted by order
44  m_lastUpdatedSimulator = simulator;
45 
46  switch (simulator.getSimulator())
47  {
48  case CSimulatorInfo::FSX: m_distributorsFsx = d; break;
49  case CSimulatorInfo::P3D: m_distributorsP3d = d; break;
50  case CSimulatorInfo::FS9: m_distributorsFs9 = d; break;
51  case CSimulatorInfo::FG: m_distributorsFG = d; break;
52  case CSimulatorInfo::XPLANE: m_distributorsXPlane = d; break;
53  case CSimulatorInfo::MSFS: m_distributorsMsfs = d; break;
54  case CSimulatorInfo::MSFS2024: m_distributorsMsfs2024 = d; break;
55  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
56  }
57  }
58 
60  {
61  Q_UNUSED(i18n);
62  static const QString p("Preferences FSX %1, P3D %2, FS9 %3, XP %4 FG %5");
63  return p.arg(m_distributorsFsx.size())
64  .arg(m_distributorsP3d.size())
65  .arg(m_distributorsFs9.size())
66  .arg(m_distributorsXPlane.size())
67  .arg(m_distributorsFG.size());
68  }
69 } // namespace swift::misc::simulation
size_type size() const
Returns number of elements in the sequence.
Definition: sequence.h:273
const_reference frontOrDefault() const
Access the first element, or a default-initialized value if the sequence is empty.
Definition: sequence.h:239
void sortAscendingByOrder()
Sort ascending.
Definition: orderablelist.h:24
Value object encapsulating information of software distributor.
Definition: distributor.h:33
Value object encapsulating a list of distributors.
CDistributor getFirstOrDefaultDistributor(const CSimulatorInfo &simulator) const
Get distributor for simulator.
const CDistributorList & getDistributors(const CSimulatorInfo &simulator) const
Get distributors.
void setDistributors(const CDistributorList &distributors, const CSimulatorInfo &simulator)
Get distributors.
QString convertToQString(bool i18n=false) const
Cast as QString.
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
bool isSingleSimulator() const
Single simulator selected.
Simulator getSimulator() const
Simulator.
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67