Ref T298, move matcher setup into BlackMisc::Simulation

This commit is contained in:
Klaus Basan
2018-08-05 23:13:18 +02:00
parent c0ca56ee93
commit 264ef7f5cb
7 changed files with 197 additions and 146 deletions

View File

@@ -0,0 +1,91 @@
/* Copyright (C) 2018
* 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 "aircraftmatchersetup.h"
namespace BlackMisc
{
namespace Simulation
{
QString CAircraftMatcherSetup::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return modeToString(this->getMatchingMode());
}
CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexMatchingMode: return CVariant::fromValue(m_mode);
default: break;
}
return CValueObject::propertyByIndex(index);
}
void CAircraftMatcherSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
{
if (index.isMyself()) { (*this) = variant.to<CAircraftMatcherSetup>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexMatchingMode: m_mode = variant.toInt(); break;
default: break;
}
CValueObject::setPropertyByIndex(index, variant);
}
const QString &CAircraftMatcherSetup::modeFlagToString(MatchingModeFlag modeFlag)
{
static const QString ms("by model string");
static const QString icao("by ICAO");
static const QString family("by family");
static const QString livery("by livery");
static const QString combined("by combined combined");
switch (modeFlag)
{
case ByModelString: return ms;
case ByIcaoData: return icao;
case ByFamily: return family;
case ByLivery: return livery;
case ByCombinedType: return combined;
default: break;
}
static const QString unknown("unknown");
return unknown;
}
QString CAircraftMatcherSetup::modeToString(MatchingMode mode)
{
if (mode == ModeAll) { return "all"; }
QStringList modes;
if (mode.testFlag(ByModelString)) { modes << modeFlagToString(ByModelString); }
if (mode.testFlag(ByIcaoData)) { modes << modeFlagToString(ByIcaoData); }
if (mode.testFlag(ByFamily)) { modes << modeFlagToString(ByFamily); }
if (mode.testFlag(ByLivery)) { modes << modeFlagToString(ByLivery); }
if (mode.testFlag(ByCombinedType)) { modes << modeFlagToString(ByCombinedType); }
return modes.join(", ");
}
CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType)
{
MatchingMode mode = byModelString ? ByModelString : ModeNone;
if (byIcaoData) { mode |= ByIcaoData; }
if (byFamily) { mode |= ByFamily; }
if (byLivery) { mode |= ByLivery; }
if (byCombinedType) { mode |= ByCombinedType; }
return mode;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,89 @@
/* Copyright (C) 2018
* 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_AIRCRAFTMATCHERSETUP_H
#define BLACKMISC_SIMULATION_AIRCRAFTMATCHERSETUP_H
#include "blackmisc/valueobject.h"
#include "blackmisc/blackmiscexport.h"
namespace BlackMisc
{
namespace Simulation
{
//! Matcher settings
class BLACKMISC_EXPORT CAircraftMatcherSetup : public CValueObject<CAircraftMatcherSetup>
{
public:
//! Enabled matching mode flags
enum MatchingModeFlag
{
ByModelString = 1 << 0,
ByIcaoData = 1 << 1,
ByFamily = 1 << 2,
ByLivery = 1 << 3,
ByCombinedType = 1 << 4,
ModeAll = ByModelString | ByIcaoData | ByFamily | ByLivery | ByCombinedType,
ModeNone = 0
};
Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag)
//! Properties by index
enum ColumnIndex
{
IndexMatchingMode = CPropertyIndex::GlobalIndexCAircraftMatcherSetup
};
//! Constructor
CAircraftMatcherSetup() {}
//! Matching mode
MatchingMode getMatchingMode() const { return static_cast<MatchingMode>(m_mode); }
//! Dynamic offset values?
void setMatchingMode(MatchingMode mode) { m_mode = static_cast<int>(mode); }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
//! Enumeration as string
static const QString &modeFlagToString(MatchingModeFlag modeFlag);
//! Enumeration as string
static QString modeToString(MatchingMode mode);
//! Mode by flags
static MatchingMode matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType);
private:
int m_mode = static_cast<int>(ModeAll);
BLACK_METACLASS(
CAircraftMatcherSetup,
BLACK_METAMEMBER(mode)
);
};
} // ns
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode)
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingModeFlag)
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode)
#endif // guard

View File

@@ -49,6 +49,10 @@ namespace BlackMisc
CSwiftPluginSettings::registerMetadata();
CVPilotModelRule::registerMetadata();
CVPilotModelRuleSet::registerMetadata();
qRegisterMetaType<CAircraftMatcherSetup::MatchingMode>();
qRegisterMetaType<CAircraftMatcherSetup::MatchingModeFlag>();
qDBusRegisterMetaType<CAircraftMatcherSetup::MatchingModeFlag>();
CAircraftMatcherSetup::registerMetadata();
}
} // ns
} // ns

View File

@@ -15,6 +15,7 @@
* \brief Generic simulation related class, but not OS or driver dependent
*/
#include "blackmisc/simulation/aircraftmatchersetup.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/simulation/airspaceaircraftsnapshot.h"
#include "blackmisc/simulation/distributorlist.h"