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  {
14  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
15  switch (simulator.getSimulator())
16  {
17  case CSimulatorInfo::FSX: return m_distributorsFsx;
18  case CSimulatorInfo::P3D: return m_distributorsP3d;
19  case CSimulatorInfo::FS9: return m_distributorsFs9;
20  case CSimulatorInfo::FG: return m_distributorsFG;
21  case CSimulatorInfo::XPLANE: return m_distributorsXPlane;
22  case CSimulatorInfo::MSFS: return m_distributorsMsfs;
23  case CSimulatorInfo::MSFS2024: return m_distributorsMsfs2024;
24  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
25  }
26 
27  static const CDistributorList empty;
28  return empty;
29  }
30 
32  {
33  return this->getDistributors(simulator).frontOrDefault();
34  }
35 
37  const CSimulatorInfo &simulator)
38  {
39  Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
40  CDistributorList d(distributors);
41  d.sortAscendingByOrder(); // make sure we are sorted by order
42  m_lastUpdatedSimulator = simulator;
43 
44  switch (simulator.getSimulator())
45  {
46  case CSimulatorInfo::FSX: m_distributorsFsx = d; break;
47  case CSimulatorInfo::P3D: m_distributorsP3d = d; break;
48  case CSimulatorInfo::FS9: m_distributorsFs9 = d; break;
49  case CSimulatorInfo::FG: m_distributorsFG = d; break;
50  case CSimulatorInfo::XPLANE: m_distributorsXPlane = d; break;
51  case CSimulatorInfo::MSFS: m_distributorsMsfs = d; break;
52  case CSimulatorInfo::MSFS2024: m_distributorsMsfs2024 = d; break;
53  default: Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator"); break;
54  }
55  }
56 
58  {
59  Q_UNUSED(i18n);
60  static const QString p("Preferences FSX %1, P3D %2, FS9 %3, XP %4 FG %5");
61  return p.arg(m_distributorsFsx.size())
62  .arg(m_distributorsP3d.size())
63  .arg(m_distributorsFs9.size())
64  .arg(m_distributorsXPlane.size())
65  .arg(m_distributorsFG.size());
66  }
67 } // 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.
QString arg(Args &&... args) const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
Definition: valueobject.h:67