mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Ref T298, added algorithm and score values to matching setup
This commit is contained in:
@@ -8,15 +8,23 @@
|
||||
*/
|
||||
|
||||
#include "aircraftmatchersetup.h"
|
||||
#include <QStringBuilder>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
CAircraftMatcherSetup::CAircraftMatcherSetup(CAircraftMatcherSetup::MatchingAlgorithm algorithm, MatchingMode mode)
|
||||
{
|
||||
this->setMatchingAlgorithm(algorithm);
|
||||
this->setMatchingMode(mode);
|
||||
}
|
||||
|
||||
QString CAircraftMatcherSetup::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return modeToString(this->getMatchingMode());
|
||||
return QStringLiteral("algorithm: '") % this->getMatchingAlgorithmAsString() %
|
||||
QStringLiteral("' mode: ") % this->getMatchingModeAsString();
|
||||
}
|
||||
|
||||
CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const
|
||||
@@ -25,6 +33,7 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMatchingAlgorithm: return CVariant::fromValue(m_algorithm);
|
||||
case IndexMatchingMode: return CVariant::fromValue(m_mode);
|
||||
default: break;
|
||||
}
|
||||
@@ -37,19 +46,37 @@ namespace BlackMisc
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMatchingAlgorithm: m_algorithm = variant.toInt(); break;
|
||||
case IndexMatchingMode: m_mode = variant.toInt(); break;
|
||||
default: break;
|
||||
}
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
}
|
||||
|
||||
const QString &CAircraftMatcherSetup::algorithmToString(CAircraftMatcherSetup::MatchingAlgorithm algorithm)
|
||||
{
|
||||
static const QString s("score based");
|
||||
static const QString r("stepwise reduce");
|
||||
switch (algorithm)
|
||||
{
|
||||
case MatchingStepwiseReduce: return r;
|
||||
case MatchingScoreBased:
|
||||
default: break;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
const QString &CAircraftMatcherSetup::modeFlagToString(MatchingModeFlag modeFlag)
|
||||
{
|
||||
static const QString ms("by model string");
|
||||
static const QString icao("by ICAO");
|
||||
static const QString icaoAircraft("by ICAO, aircraft first");
|
||||
static const QString icaoAirline("by ICAO, airline first");
|
||||
static const QString family("by family");
|
||||
static const QString livery("by livery");
|
||||
static const QString combined("by combined combined");
|
||||
static const QString noZeros("scoring, ignore zero scores");
|
||||
static const QString preferColorLiveries("scoring, prefer color liveries");
|
||||
|
||||
switch (modeFlag)
|
||||
{
|
||||
@@ -58,6 +85,10 @@ namespace BlackMisc
|
||||
case ByFamily: return family;
|
||||
case ByLivery: return livery;
|
||||
case ByCombinedType: return combined;
|
||||
case ByIcaoOrderAircraftFirst: return icaoAircraft;
|
||||
case ByIcaoOrderAirlineFirst: return icaoAirline;
|
||||
case ScoreIgnoreZeros: return noZeros;
|
||||
case ScorePreferColorLiveries: return preferColorLiveries;
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -67,24 +98,31 @@ namespace BlackMisc
|
||||
|
||||
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); }
|
||||
if (mode.testFlag(ByIcaoOrderAircraftFirst)) { modes << modeFlagToString(ByIcaoOrderAircraftFirst); }
|
||||
if (mode.testFlag(ByIcaoOrderAirlineFirst)) { modes << modeFlagToString(ByIcaoOrderAirlineFirst); }
|
||||
if (mode.testFlag(ByFamily)) { modes << modeFlagToString(ByFamily); }
|
||||
if (mode.testFlag(ByLivery)) { modes << modeFlagToString(ByLivery); }
|
||||
if (mode.testFlag(ByCombinedType)) { modes << modeFlagToString(ByCombinedType); }
|
||||
if (mode.testFlag(ScoreIgnoreZeros)) { modes << modeFlagToString(ScoreIgnoreZeros); }
|
||||
if (mode.testFlag(ScorePreferColorLiveries)) { modes << modeFlagToString(ScorePreferColorLiveries); }
|
||||
return modes.join(", ");
|
||||
}
|
||||
|
||||
CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType)
|
||||
CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode(
|
||||
bool byModelString, bool byIcaoDataAircraft1st, bool byIcaoDataAirline1st, bool byFamily, bool byLivery, bool byCombinedType,
|
||||
bool scoreIgnoreZeros, bool scorePreferColorLiveries)
|
||||
{
|
||||
MatchingMode mode = byModelString ? ByModelString : ModeNone;
|
||||
if (byIcaoData) { mode |= ByIcaoData; }
|
||||
if (byFamily) { mode |= ByFamily; }
|
||||
if (byLivery) { mode |= ByLivery; }
|
||||
if (byCombinedType) { mode |= ByCombinedType; }
|
||||
if (byIcaoDataAircraft1st) { mode |= ByIcaoOrderAircraftFirst; }
|
||||
if (byIcaoDataAirline1st) { mode |= ByIcaoOrderAirlineFirst; }
|
||||
if (byFamily) { mode |= ByFamily; }
|
||||
if (byLivery) { mode |= ByLivery; }
|
||||
if (byCombinedType) { mode |= ByCombinedType; }
|
||||
if (scoreIgnoreZeros) { mode |= ScoreIgnoreZeros; }
|
||||
if (scorePreferColorLiveries) { mode |= ScorePreferColorLiveries; }
|
||||
return mode;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -24,31 +24,61 @@ namespace BlackMisc
|
||||
class BLACKMISC_EXPORT CAircraftMatcherSetup : public CValueObject<CAircraftMatcherSetup>
|
||||
{
|
||||
public:
|
||||
//! Matching algorithm
|
||||
enum MatchingAlgorithm
|
||||
{
|
||||
MatchingScoreBased,
|
||||
MatchingStepwiseReduce
|
||||
};
|
||||
|
||||
//! Enabled matching mode flags
|
||||
enum MatchingModeFlag
|
||||
{
|
||||
ByModelString = 1 << 0,
|
||||
ByModelString = 1 << 0, //!< allow exact model string match
|
||||
ByIcaoData = 1 << 1,
|
||||
ByFamily = 1 << 2,
|
||||
ByLivery = 1 << 3,
|
||||
ByCombinedType = 1 << 4,
|
||||
ModeAll = ByModelString | ByIcaoData | ByFamily | ByLivery | ByCombinedType,
|
||||
ModeNone = 0
|
||||
ByIcaoOrderAircraftFirst = (1 << 5) | ByIcaoData,
|
||||
ByIcaoOrderAirlineFirst = (1 << 6) | ByIcaoData,
|
||||
// --- score based matching ---
|
||||
ScoreIgnoreZeros = 1 << 7, //!< zero scores are ignored
|
||||
ScorePreferColorLiveries = 1 << 8, //!< prefer color liveries
|
||||
// --- others ---
|
||||
ModeNone = 0,
|
||||
ModeScoreDefault = ScoreIgnoreZeros | ScorePreferColorLiveries,
|
||||
ModeDefault = ByModelString | ByFamily | ByLivery | ByCombinedType | ByIcaoOrderAircraftFirst | ModeScoreDefault
|
||||
};
|
||||
Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag)
|
||||
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexMatchingMode = CPropertyIndex::GlobalIndexCAircraftMatcherSetup
|
||||
IndexMatchingAlgorithm = CPropertyIndex::GlobalIndexCAircraftMatcherSetup,
|
||||
IndexMatchingMode
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
CAircraftMatcherSetup() {}
|
||||
|
||||
//! Constructor
|
||||
CAircraftMatcherSetup(MatchingAlgorithm algorithm, MatchingMode mode);
|
||||
|
||||
//! Algorithm
|
||||
MatchingAlgorithm getMatchingAlgorithm() const { return static_cast<MatchingAlgorithm>(m_algorithm); }
|
||||
|
||||
//! Algorithm as string
|
||||
const QString &getMatchingAlgorithmAsString() const { return algorithmToString(this->getMatchingAlgorithm()); }
|
||||
|
||||
//! Algorithm
|
||||
void setMatchingAlgorithm(MatchingAlgorithm algorithm) { m_algorithm = static_cast<int>(algorithm); }
|
||||
|
||||
//! Matching mode
|
||||
MatchingMode getMatchingMode() const { return static_cast<MatchingMode>(m_mode); }
|
||||
|
||||
//! Matching mode as string
|
||||
QString getMatchingModeAsString() const { return modeToString(this->getMatchingMode()); }
|
||||
|
||||
//! Dynamic offset values?
|
||||
void setMatchingMode(MatchingMode mode) { m_mode = static_cast<int>(mode); }
|
||||
|
||||
@@ -61,6 +91,9 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant);
|
||||
|
||||
//! Algorithm to string
|
||||
static const QString &algorithmToString(MatchingAlgorithm algorithm);
|
||||
|
||||
//! Enumeration as string
|
||||
static const QString &modeFlagToString(MatchingModeFlag modeFlag);
|
||||
|
||||
@@ -68,13 +101,17 @@ namespace BlackMisc
|
||||
static QString modeToString(MatchingMode mode);
|
||||
|
||||
//! Mode by flags
|
||||
static MatchingMode matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType);
|
||||
static MatchingMode matchingMode(
|
||||
bool byModelString, bool byIcaoDataAircraft1st, bool byIcaoDataAirline1st, bool byFamily, bool byLivery, bool byCombinedType,
|
||||
bool scoreIgnoreZeros, bool scorePreferColorLiveries);
|
||||
|
||||
private:
|
||||
int m_mode = static_cast<int>(ModeAll);
|
||||
int m_algorithm = static_cast<int>(MatchingScoreBased);
|
||||
int m_mode = static_cast<int>(ModeDefault);
|
||||
|
||||
BLACK_METACLASS(
|
||||
CAircraftMatcherSetup,
|
||||
BLACK_METAMEMBER(algorithm),
|
||||
BLACK_METAMEMBER(mode)
|
||||
);
|
||||
};
|
||||
@@ -82,6 +119,7 @@ namespace BlackMisc
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingAlgorithm)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode)
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingModeFlag)
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode)
|
||||
|
||||
@@ -49,8 +49,10 @@ namespace BlackMisc
|
||||
CSwiftPluginSettings::registerMetadata();
|
||||
CVPilotModelRule::registerMetadata();
|
||||
CVPilotModelRuleSet::registerMetadata();
|
||||
qRegisterMetaType<CAircraftMatcherSetup::MatchingAlgorithm>();
|
||||
qRegisterMetaType<CAircraftMatcherSetup::MatchingMode>();
|
||||
qRegisterMetaType<CAircraftMatcherSetup::MatchingModeFlag>();
|
||||
qDBusRegisterMetaType<CAircraftMatcherSetup::MatchingAlgorithm>();
|
||||
qDBusRegisterMetaType<CAircraftMatcherSetup::MatchingModeFlag>();
|
||||
CAircraftMatcherSetup::registerMetadata();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user