mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
refs #640, distributor list preferences value object and settings
This commit is contained in:
68
src/blackmisc/simulation/distributorlistpreferences.cpp
Normal file
68
src/blackmisc/simulation/distributorlistpreferences.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/distributorlistpreferences.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CDistributorListPreferences::CDistributorListPreferences() { }
|
||||
|
||||
void CDistributorListPreferences::registerMetadata()
|
||||
{
|
||||
CValueObject<CDistributorListPreferences>::registerMetadata();
|
||||
}
|
||||
|
||||
const CDistributorList &CDistributorListPreferences::getDistributors(const CSimulatorInfo &simulator) const
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FSX: return this->m_distributorsFsx;
|
||||
case CSimulatorInfo::P3D: return this->m_distributorsP3d;
|
||||
case CSimulatorInfo::FS9: return this->m_distributorsFs9;
|
||||
case CSimulatorInfo::XPLANE: return this->m_distributorsXPlane;
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
|
||||
static const CDistributorList empty;
|
||||
return empty;
|
||||
}
|
||||
|
||||
void CDistributorListPreferences::setDistributors(const CDistributorList &distributors, const CSimulatorInfo &simulator)
|
||||
{
|
||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
|
||||
CDistributorList d(distributors);
|
||||
d.sortAscendingByOrder(); // make sure we are sorted by order
|
||||
this->m_lastUpdatedSimulator = simulator;
|
||||
|
||||
switch (simulator.getSimulator())
|
||||
{
|
||||
case CSimulatorInfo::FSX: this->m_distributorsFsx = d; break;
|
||||
case CSimulatorInfo::P3D: this->m_distributorsP3d = d; break;
|
||||
case CSimulatorInfo::FS9: this->m_distributorsFs9 = d; break;
|
||||
case CSimulatorInfo::XPLANE: this->m_distributorsXPlane = d; break;
|
||||
default:
|
||||
Q_ASSERT_X(false, Q_FUNC_INFO, "Wrong simulator");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CDistributorListPreferences::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
static const QString p("Preferences FSX %1, P3D %2, FS9 %3, XP %4");
|
||||
return p.arg(this->m_distributorsFsx.size()).arg(this->m_distributorsP3d.size()).arg(this->m_distributorsFs9.size()).arg(this->m_distributorsXPlane.size());
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
66
src/blackmisc/simulation/distributorlistpreferences.h
Normal file
66
src/blackmisc/simulation/distributorlistpreferences.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 2016
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SIMULATION_DISTRIBUTORLISTPREFRENCES_H
|
||||
#define BLACKMISC_SIMULATION_DISTRIBUTORLISTPREFRENCES_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
//! Preferences for distributors
|
||||
class BLACKMISC_EXPORT CDistributorListPreferences :
|
||||
public CValueObject<CDistributorListPreferences>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CDistributorListPreferences();
|
||||
|
||||
//! \copydoc BlackMisc::CValueObject::registerMetadata
|
||||
static void registerMetadata();
|
||||
|
||||
//! Get distributors
|
||||
const CDistributorList &getDistributors(const CSimulatorInfo &simulator) const;
|
||||
|
||||
//! Last updated simulator
|
||||
const CSimulatorInfo &getLastUpdatedSimulator() const { return m_lastUpdatedSimulator; }
|
||||
|
||||
//! Get distributors
|
||||
void setDistributors(const CDistributorList &distributors, const CSimulatorInfo &simulator);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
CDistributorList m_distributorsFsx;
|
||||
CDistributorList m_distributorsP3d;
|
||||
CDistributorList m_distributorsFs9;
|
||||
CDistributorList m_distributorsXPlane;
|
||||
CSimulatorInfo m_lastUpdatedSimulator;
|
||||
|
||||
BLACK_METACLASS(
|
||||
CDistributorListPreferences,
|
||||
BLACK_METAMEMBER(distributorsFsx),
|
||||
BLACK_METAMEMBER(distributorsP3d),
|
||||
BLACK_METAMEMBER(distributorsFs9),
|
||||
BLACK_METAMEMBER(distributorsXPlane)
|
||||
);
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CDistributorListPreferences)
|
||||
|
||||
#endif //guard
|
||||
@@ -27,6 +27,7 @@ namespace BlackMisc
|
||||
CAirspaceAircraftSnapshot::registerMetadata();
|
||||
CDistributor::registerMetadata();
|
||||
CDistributorList::registerMetadata();
|
||||
CDistributorListPreferences::registerMetadata();
|
||||
CSimConnectUtilities::registerMetadata();
|
||||
CSimulatedAircraft::registerMetadata();
|
||||
CSimulatedAircraftList::registerMetadata();
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "blackmisc/simulation/simulatorplugininfolist.h"
|
||||
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
|
||||
#include "blackmisc/simulation/distributorlist.h"
|
||||
#include "blackmisc/simulation/distributorlistpreferences.h"
|
||||
#include "blackmisc/simulation/simulatorsetup.h"
|
||||
#include "blackmisc/simulation/simulatorinfolist.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
|
||||
Reference in New Issue
Block a user