Ref T298, added algorithm and score values to matching setup

This commit is contained in:
Klaus Basan
2018-08-07 19:54:47 +02:00
parent bd8d11d9d6
commit 8b6bdf2276
9 changed files with 276 additions and 53 deletions

View File

@@ -9,10 +9,10 @@
#include "settingsmatchingcomponent.h"
#include "ui_settingsmatchingcomponent.h"
#include "blackgui/guiapplication.h"
#include "blackcore/context/contextsimulator.h"
#include "blackmisc/simulation/aircraftmatchersetup.h"
#include <QPointer>
using namespace BlackMisc::Simulation;
using namespace BlackCore::Context;
@@ -28,6 +28,7 @@ namespace BlackGui
ui->setupUi(this);
connect(ui->pb_Save, &QPushButton::released, this, &CSettingsMatchingComponent::onSavePressed);
connect(ui->pb_Reload, &QPushButton::released, this, &CSettingsMatchingComponent::onReloadPressed);
this->deferredReload(5000);
}
CSettingsMatchingComponent::~CSettingsMatchingComponent()
@@ -43,10 +44,27 @@ namespace BlackGui
void CSettingsMatchingComponent::onReloadPressed()
{
IContextSimulator *simContext = simulatorContext();
if (!simContext) { return; }
const CAircraftMatcherSetup setup = simContext->getMatchingSetup();
ui->editor_MatchingForm->setValue(setup);
this->deferredReload(0);
}
void CSettingsMatchingComponent::deferredReload(int deferMs)
{
if (deferMs < 1)
{
IContextSimulator *simContext = simulatorContext();
if (!simContext) { return; }
const CAircraftMatcherSetup setup = simContext->getMatchingSetup();
ui->editor_MatchingForm->setValue(setup);
}
else
{
QPointer<CSettingsMatchingComponent> myself(this);
QTimer::singleShot(deferMs, this, [ = ]
{
if (!myself) { return; }
this->deferredReload(0);
});
}
}
IContextSimulator *CSettingsMatchingComponent::simulatorContext()

View File

@@ -42,6 +42,9 @@ namespace BlackGui
//! Reload pressed
void onReloadPressed();
//! Deferred reload
void deferredReload(int deferMs);
//! Network context
static BlackCore::Context::IContextSimulator *simulatorContext();
};

View File

@@ -6,21 +6,33 @@
<rect>
<x>0</x>
<y>0</y>
<width>640</width>
<height>480</height>
<width>232</width>
<height>197</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
<string>Matching settings</string>
</property>
<layout class="QVBoxLayout" name="vl_MatchingComponent">
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="BlackGui::Editors::CMatchingForm" name="editor_MatchingForm">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
</widget>
</item>

View File

@@ -32,10 +32,17 @@ namespace BlackGui
void CMatchingForm::setReadOnly(bool readonly)
{
CGuiUtility::checkBoxReadOnly(ui->cb_ByModelString, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByICAOdata, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByIcaoDataAircraft1st, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByIcaoDataAirline1st, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByFamily, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByLivery, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ByCombinedCode, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ScoreIgnoreZeros, readonly);
CGuiUtility::checkBoxReadOnly(ui->cb_ScorePreferColorLiveries, readonly);
const bool enabled = !readonly;
ui->rb_Reduction->setEnabled(enabled);
ui->rb_ScoreBased->setEnabled(enabled);
}
CStatusMessageList CMatchingForm::validate(bool withNestedForms) const
@@ -49,24 +56,49 @@ namespace BlackGui
const CAircraftMatcherSetup::MatchingMode mode = setup.getMatchingMode();
ui->cb_ByModelString->setChecked(mode.testFlag(CAircraftMatcherSetup::ByModelString));
ui->cb_ByCombinedCode->setChecked(mode.testFlag(CAircraftMatcherSetup::ByCombinedType));
ui->cb_ByICAOdata->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoData));
ui->cb_ByIcaoDataAircraft1st->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoOrderAircraftFirst));
ui->cb_ByIcaoDataAirline1st->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoOrderAirlineFirst));
ui->cb_ByLivery->setChecked(mode.testFlag(CAircraftMatcherSetup::ByLivery));
ui->cb_ByFamily->setChecked(mode.testFlag(CAircraftMatcherSetup::ByFamily));
ui->cb_ScoreIgnoreZeros->setChecked(mode.testFlag(CAircraftMatcherSetup::ScoreIgnoreZeros));
ui->cb_ScorePreferColorLiveries->setChecked(mode.testFlag(CAircraftMatcherSetup::ScorePreferColorLiveries));
if (setup.getMatchingAlgorithm() == CAircraftMatcherSetup::MatchingScoreBased)
{
ui->rb_ScoreBased->setChecked(true);
}
else
{
ui->rb_Reduction->setChecked(true);
}
}
CAircraftMatcherSetup CMatchingForm::value() const
{
CAircraftMatcherSetup setup;
setup.setMatchingMode(matchingMode());
const CAircraftMatcherSetup setup(algorithm(), matchingMode());
return setup;
}
void CMatchingForm::clear()
{
CAircraftMatcherSetup s;
this->setValue(s);
}
CAircraftMatcherSetup::MatchingAlgorithm CMatchingForm::algorithm() const
{
if (ui->rb_Reduction->isChecked()) { return CAircraftMatcherSetup::MatchingStepwiseReduce; }
return CAircraftMatcherSetup::MatchingScoreBased;
}
CAircraftMatcherSetup::MatchingMode CMatchingForm::matchingMode() const
{
return CAircraftMatcherSetup::matchingMode(
ui->cb_ByModelString->isChecked(), ui->cb_ByICAOdata->isChecked(),
ui->cb_ByModelString->isChecked(),
ui->cb_ByIcaoDataAircraft1st->isChecked(), ui->cb_ByIcaoDataAirline1st->isChecked(),
ui->cb_ByFamily->isChecked(), ui->cb_ByLivery->isChecked(),
ui->cb_ByCombinedCode->isChecked()
ui->cb_ByCombinedCode->isChecked(),
ui->cb_ScoreIgnoreZeros->isChecked(), ui->cb_ScorePreferColorLiveries->isChecked()
);
}
} // ns

View File

@@ -49,6 +49,9 @@ namespace BlackGui
void clear();
private:
//! Algorithm
BlackMisc::Simulation::CAircraftMatcherSetup::MatchingAlgorithm algorithm() const;
//! Mode
BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode matchingMode() const;

View File

@@ -6,20 +6,69 @@
<rect>
<x>0</x>
<y>0</y>
<width>287</width>
<height>87</height>
<width>243</width>
<height>239</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<layout class="QVBoxLayout" name="vl_MatchingForm">
<property name="leftMargin">
<number>5</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>5</number>
</property>
<property name="bottomMargin">
<number>5</number>
</property>
<item>
<widget class="QGroupBox" name="gb_Mode">
<widget class="QGroupBox" name="gb_Algorithm">
<property name="title">
<string>Mode</string>
<string>Algorithm</string>
</property>
<layout class="QHBoxLayout" name="hl_Algorithm">
<item>
<widget class="QRadioButton" name="rb_ScoreBased">
<property name="text">
<string>reduction, then score based</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rb_Reduction">
<property name="text">
<string>reduction</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_Reduction">
<property name="title">
<string>Reduction</string>
</property>
<layout class="QGridLayout" name="gl_Mode">
<item row="2" column="0">
<widget class="QCheckBox" name="cb_ByFamily">
<property name="text">
<string>by family</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="cb_ByCombinedCode">
<property name="text">
<string>combined code</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="cb_ByModelString">
<property name="text">
@@ -27,28 +76,21 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="cb_ByICAOdata">
<item row="1" column="1">
<widget class="QCheckBox" name="cb_ByIcaoDataAirline1st">
<property name="text">
<string>by ICAO data</string>
<string>by ICAO: airline first</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="cb_ByFamily">
<widget class="QCheckBox" name="cb_ByIcaoDataAircraft1st">
<property name="text">
<string>by family</string>
<string>by ICAO: aircraft first</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="cb_ByCombinedCode">
<property name="text">
<string>combined code</string>
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="1">
<widget class="QCheckBox" name="cb_ByLivery">
<property name="text">
<string>by livery</string>
@@ -58,8 +100,43 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_Scoring">
<property name="title">
<string>Scoring</string>
</property>
<layout class="QHBoxLayout" name="hl_Scoring">
<item>
<widget class="QCheckBox" name="cb_ScorePreferColorLiveries">
<property name="text">
<string>prefer color liveries</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_ScoreIgnoreZeros">
<property name="text">
<string>ignore 0 (zero) scores</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>rb_ScoreBased</tabstop>
<tabstop>rb_Reduction</tabstop>
<tabstop>cb_ByModelString</tabstop>
<tabstop>cb_ByIcaoDataAircraft1st</tabstop>
<tabstop>cb_ByIcaoDataAirline1st</tabstop>
<tabstop>cb_ByFamily</tabstop>
<tabstop>cb_ByLivery</tabstop>
<tabstop>cb_ByCombinedCode</tabstop>
<tabstop>cb_ScorePreferColorLiveries</tabstop>
<tabstop>cb_ScoreIgnoreZeros</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

View File

@@ -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

View File

@@ -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)

View File

@@ -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();
}