diff --git a/src/blackmisc/simulation/distributorlist.cpp b/src/blackmisc/simulation/distributorlist.cpp index c0efc4747..c6ce43b46 100644 --- a/src/blackmisc/simulation/distributorlist.cpp +++ b/src/blackmisc/simulation/distributorlist.cpp @@ -50,7 +50,7 @@ namespace BlackMisc { if (distributor.matchesKeyOrAlias(keyOrAlias)) { return true; } } - return true; + return false; } QStringList CDistributorList::getDbKeysAndAliases() const diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 3f9260fed..24027fdbe 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -31,6 +31,7 @@ namespace BlackMisc CSimulatedAircraft::registerMetadata(); CSimulatedAircraftList::registerMetadata(); CSimulatorInfo::registerMetadata(); + CSimulatorInfoList::registerMetadata(); CSimulatorPluginInfo::registerMetadata(); CSimulatorPluginInfoList::registerMetadata(); CSimulatorSetup::registerMetadata(); diff --git a/src/blackmisc/simulation/simulation.h b/src/blackmisc/simulation/simulation.h index f1f41370c..d4d4424bd 100644 --- a/src/blackmisc/simulation/simulation.h +++ b/src/blackmisc/simulation/simulation.h @@ -21,7 +21,7 @@ #include "blackmisc/simulation/airspaceaircraftsnapshot.h" #include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/simulatorsetup.h" -#include "blackmisc/simulation/simulatorinfo.h" +#include "blackmisc/simulation/simulatorinfolist.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" #include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h" #include "blackmisc/simulation/fscommon/vpilotmodelruleset.h" diff --git a/src/blackmisc/simulation/simulatorinfo.h b/src/blackmisc/simulation/simulatorinfo.h index ffaecc3c9..6a2883ee1 100644 --- a/src/blackmisc/simulation/simulatorinfo.h +++ b/src/blackmisc/simulation/simulatorinfo.h @@ -32,7 +32,6 @@ namespace BlackMisc class BLACKMISC_EXPORT CSimulatorInfo : public BlackMisc::CValueObject { public: - //! Simulator enum SimulatorFlag { diff --git a/src/blackmisc/simulation/simulatorinfolist.cpp b/src/blackmisc/simulation/simulatorinfolist.cpp new file mode 100644 index 000000000..0397df4fa --- /dev/null +++ b/src/blackmisc/simulation/simulatorinfolist.cpp @@ -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/simulatorinfolist.h" +#include "blackmisc/predicates.h" + +namespace BlackMisc +{ + namespace Simulation + { + CSimulatorInfoList::CSimulatorInfoList() { } + + CSimulatorInfoList::CSimulatorInfoList(const CSequence &other) : + CSequence(other) + { } + + CSimulatorInfoList CSimulatorInfoList::withNoDuplicates() const + { + if (this->isEmpty()) { return CSimulatorInfoList(); } + QList simIndexes; + CSimulatorInfoList newList; + for (const CSimulatorInfo &simulator : *this) + { + const int i = static_cast(simulator.getSimulator()); + if (simIndexes.contains(i)) { continue; } + newList.push_back(simulator); + simIndexes.append(i); + } + return newList; + } + + CSimulatorInfoList CSimulatorInfoList::splitIntoSingleSimulators() const + { + if (this->isEmpty()) { return CSimulatorInfoList(); } + CSimulatorInfoList newList; + for (const CSimulatorInfo &simulator : *this) + { + if (simulator.isUnspecified() || simulator.isNoSimulator()) { continue; } + if (simulator.isSingleSimulator()) + { + newList.push_back(simulator); + } + else + { + newList.push_back(splitIntoSingleSimulators(simulator)); + } + } + return newList; + } + + CSimulatorInfoList CSimulatorInfoList::splitIntoSingleSimulators(const CSimulatorInfo &sim) + { + CSimulatorInfoList sims; + if (sim.fs9()) { sims.push_back(CSimulatorInfo(CSimulatorInfo::FS9)); } + if (sim.fsx()) { sims.push_back(CSimulatorInfo(CSimulatorInfo::FSX)); } + if (sim.p3d()) { sims.push_back(CSimulatorInfo(CSimulatorInfo::P3D)); } + if (sim.xplane()) { sims.push_back(CSimulatorInfo(CSimulatorInfo::XPLANE)); } + return sims; + } + + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/simulatorinfolist.h b/src/blackmisc/simulation/simulatorinfolist.h new file mode 100644 index 000000000..4589bd3aa --- /dev/null +++ b/src/blackmisc/simulation/simulatorinfolist.h @@ -0,0 +1,56 @@ +/* Copyright (C) 2015 + * 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_SIMULATORINFOLIST_H +#define BLACKMISC_SIMULATION_SIMULATORINFOLIST_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/simulation/simulatorinfo.h" +#include "blackmisc/collection.h" +#include "blackmisc/sequence.h" +#include +#include + +namespace BlackMisc +{ + namespace Simulation + { + //! Value object encapsulating a list of distributors. + class BLACKMISC_EXPORT CSimulatorInfoList : + public BlackMisc::CSequence, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CSimulatorInfoList) + + //! Default constructor. + CSimulatorInfoList(); + + //! Construct from a base class object. + CSimulatorInfoList(const CSequence &other); + + //! Find by id or alias + CSimulatorInfoList withNoDuplicates() const; + + //! Split into single simulators, unknown simulators are ignored + CSimulatorInfoList splitIntoSingleSimulators() const; + + //! Split into single simulators, unknown simulators are ignored + static CSimulatorInfoList splitIntoSingleSimulators(const CSimulatorInfo &sim); + }; + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Simulation::CSimulatorInfoList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard