refs #634, a component allowing to test model matching

* adjusted corresponding components
* new component for matcher
This commit is contained in:
Klaus Basan
2016-04-04 13:02:09 +02:00
parent aa6370c325
commit b567e2e57b
8 changed files with 562 additions and 19 deletions

View File

@@ -11,6 +11,7 @@
#include "ui_dbmappingcomponent.h"
#include "blackgui/components/dbautostashingcomponent.h"
#include "blackgui/components/dbmodelmappingmodifycomponent.h"
#include "blackgui/components/modelmatchercomponent.h"
#include "blackgui/guiapplication.h"
#include "blackgui/guiutility.h"
#include "blackgui/shortcut.h"
@@ -68,7 +69,8 @@ namespace BlackGui
connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished);
connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged);
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::tabIndexChanged);
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged);
connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged);
// how to display forms
ui->editor_AircraftIcao->setSelectOnly();
@@ -454,6 +456,30 @@ namespace BlackGui
}
}
void CDbMappingComponent::ps_tabIndexChanged(int index)
{
TabIndex ti = static_cast<CDbMappingComponent::TabIndex>(index);
switch (ti)
{
case CDbMappingComponent::TabOwnModelSet:
ui->frp_Editors->setVisible(true);
ui->editor_Model->setVisible(true);
this->resizeForSelect();
break;
case CDbMappingComponent::TabModelMatcher:
ui->editor_Model->setVisible(false);
ui->frp_Editors->setVisible(false);
this->resizeForSelect();
break;
default:
ui->frp_Editors->setVisible(true);
ui->editor_Model->setVisible(true);
break;
}
emit this->tabIndexChanged(index);
}
void CDbMappingComponent::ps_onModelsSuccessfullyPublished(const CAircraftModelList &models)
{
if (models.isEmpty()) { return; }

View File

@@ -52,11 +52,12 @@ namespace BlackGui
//! Must match real tab index
enum TabIndex
{
NoValidTab = -1,
TabStash = 0,
TabOwnModels = 1,
TabOwnModelSet = 2,
TabVPilot = 3
NoValidTab = -1,
TabStash = 0,
TabOwnModels = 1,
TabOwnModelSet = 2,
TabModelMatcher = 3,
TabVPilot = 4
};
//! Constructor
@@ -180,6 +181,9 @@ namespace BlackGui
//! Stashed models changed
void ps_onStashedModelsChanged();
//! Tab index changed
void ps_tabIndexChanged(int index);
//! Models have been published successfully
void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models);

View File

@@ -164,6 +164,38 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_ModelMatcher">
<attribute name="title">
<string>Model matcher</string>
</attribute>
<layout class="QHBoxLayout" name="hl_ModelMatcher">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Components::CModelMatcherComponent" name="comp_ModelMatcher">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_VPilot">
<attribute name="title">
<string>vPilot rules</string>
@@ -439,6 +471,12 @@
<header>blackgui/components/dbownmodelscomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CModelMatcherComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/modelmatchercomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@@ -40,7 +40,7 @@ namespace BlackGui
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(&this->m_modelSetLoader, &CModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::rowCountChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded);
@@ -120,18 +120,13 @@ namespace BlackGui
CDbMappingComponentAware::setMappingComponent(component);
if (component)
{
connect(this->getMappingComponent(), &CDbMappingComponent::tabIndexChanged, this, &CDbOwnModelSetComponent::ps_tabChanged);
connect(this->getMappingComponent(), &CDbMappingComponent::tabIndexChanged, this, &CDbOwnModelSetComponent::ps_tabIndexChanged);
}
}
void CDbOwnModelSetComponent::ps_tabChanged(int index)
void CDbOwnModelSetComponent::ps_tabIndexChanged(int index)
{
CDbMappingComponent::TabIndex ti = static_cast<CDbMappingComponent::TabIndex>(index);
if (ti == CDbMappingComponent::TabOwnModelSet)
{
// myself
this->getMappingComponent()->resizeForSelect();
}
Q_UNUSED(index);
}
void CDbOwnModelSetComponent::ps_buttonClicked()

View File

@@ -69,7 +69,7 @@ namespace BlackGui
private slots:
//! Tab has been changed
void ps_tabChanged(int index);
void ps_tabIndexChanged(int index);
//! Button was clicked
void ps_buttonClicked();
@@ -94,9 +94,9 @@ namespace BlackGui
void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &sim);
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
BlackMisc::Simulation::CSimulatorInfo m_simulator;
BlackMisc::Simulation::CModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
BlackMisc::Simulation::CSimulatorInfo m_simulator;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
//! The menu for loading and handling own models for mapping tasks
//! \note This is specific for that very component

View File

@@ -0,0 +1,152 @@
/* 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 "modelmatchercomponent.h"
#include "guiapplication.h"
#include "guiutility.h"
#include "uppercasevalidator.h"
#include "ui_modelmatchercomponent.h"
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Network;
using namespace BlackGui::Models;
using namespace BlackCore;
namespace BlackGui
{
namespace Components
{
CModelMatcherComponent::CModelMatcherComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CModelMatcherComponent)
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui");
Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "Missing web services");
ui->setupUi(this);
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
ui->comp_AirlineSelector->withIcaoDescription(false);
ui->comp_AircraftSelector->withIcaoDescription(false);
ui->comp_LiverySelector->withLiveryDescription(false);
ui->tvp_ResultMessages->setMode(CStatusMessageListModel::Simplified);
const CUpperCaseValidator *validator = new CUpperCaseValidator(this);
ui->le_ModelString->setValidator(validator);
ui->le_Manufacturer->setValidator(validator);
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CModelMatcherComponent::ps_simulatorChanged);
connect(ui->pb_Test, &QPushButton::pressed, this, &CModelMatcherComponent::ps_test);
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::ps_webDataRed);
const CSimulatorInfo sim(ui->comp_SimulatorSelector->getValue());
this->m_modelSetLoader.changeSimulator(sim);
this->redisplay();
}
CModelMatcherComponent::~CModelMatcherComponent()
{ }
void CModelMatcherComponent::tabIndexChanged(int index)
{
if (index < 0) { return; }
QTabWidget *tw = CGuiUtility::parentTabWidget(this);
Q_ASSERT_X(tw, Q_FUNC_INFO, "Cannot find parent tab widget");
const QWidget *tabWidget = tw->currentWidget();
const QWidget *myselfTabWidget = this->parentWidget();
if (tabWidget != myselfTabWidget) { return; }
this->redisplay();
}
void CModelMatcherComponent::ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
this->m_modelSetLoader.changeSimulator(simulator);
this->m_matcher.setModelSet(this->m_modelSetLoader.getAircraftModels());
this->redisplay();
}
void CModelMatcherComponent::ps_cacheChanged(CSimulatorInfo &simulator)
{
Q_UNUSED(simulator);
this->redisplay();
}
void CModelMatcherComponent::ps_test()
{
ui->te_Results->clear();
CStatusMessageList msgs;
this->m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel());
CSimulatedAircraft remoteAircraft(createAircraft());
const CAircraftModel matched = this->m_matcher.getClosestMatch(remoteAircraft, &msgs);
remoteAircraft.setModel(matched);
ui->te_Results->setText(remoteAircraft.toQString(true));
ui->tvp_ResultMessages->updateContainer(msgs);
}
void CModelMatcherComponent::ps_webDataRed(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number)
{
if (number > 0 && entity.testFlag(CEntityFlags::ModelEntity) && state == CEntityFlags::ReadFinished)
{
QStringList modelStrings(sGui->getWebDataServices()->getModelStrings());
modelStrings.sort();
ui->le_ModelString->setCompleter(new QCompleter(modelStrings, this));
}
}
void CModelMatcherComponent::redisplay()
{
const int c = this->m_modelSetLoader.getAircraftModelsCount();
ui->le_ModelSetCount->setText(QString::number(c));
}
CSimulatedAircraft CModelMatcherComponent::createAircraft() const
{
const QString airline(ui->comp_AirlineSelector->getRawDesignator());
const QString aircraft(ui->comp_AircraftSelector->getRawDesignator());
const QString model(ui->le_ModelString->text().trimmed().toUpper());
const QString combined(ui->comp_CombinedCode->getCombinedType());
const QString manufacturer(ui->le_Manufacturer->text().trimmed().toUpper());
CCallsign cs("SWIFT");
CSimulatedAircraft sa;
if (!model.isEmpty())
{
const CAircraftModel m(model, CAircraftModel::TypeFsdData);
sa = CSimulatedAircraft(m);
}
sa.setCallsign(cs);
if (!aircraft.isEmpty())
{
CAircraftIcaoCode icao(aircraft, combined);
icao.setManufacturer(manufacturer);
sa.setAircraftIcaoCode(icao);
}
if (!airline.isEmpty())
{
const CAirlineIcaoCode al(airline);
const CLivery l(CLivery::getStandardCode(al), al, "Standard");
sa.setLivery(l);
}
return sa;
}
CAircraftModel CModelMatcherComponent::defaultModel() const
{
// can somehow dynamilcally determine the models
const CAircraftIcaoCode icaoAircraft("B737", "L2J", "FooBar", "Dummy", "M", false, false, false, 1);
const CAirlineIcaoCode icaoAirline("Foo", "FooBar airlines", { "DE", "Germany" }, "FOO", true, true);
const CLivery livery(CLivery::getStandardCode(icaoAirline), icaoAirline, "Standard Foo airlines", "red", "blue", false);
const CAircraftModel model("default model", CAircraftModel::TypeOwnSimulatorModel, "dummy model", icaoAircraft, livery);
return model;
}
} // ns
} // ns

View File

@@ -0,0 +1,78 @@
/* 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 BLACKGUI_COMPONENT_MODELMATCHERCOMPONENT_H
#define BLACKGUI_COMPONENT_MODELMATCHERCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/simulation/aircraftmodelsetloader.h"
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/aircraftmatcher.h"
#include "blackmisc/network/entityflags.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CModelMatcherComponent; }
namespace BlackGui
{
namespace Components
{
/*!
* Model matcher testing and configuration
*/
class BLACKGUI_EXPORT CModelMatcherComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CModelMatcherComponent(QWidget *parent = nullptr);
//! Destructor
~CModelMatcherComponent();
public slots:
//! Tab where this is embedded has been changed
void tabIndexChanged(int index);
private slots:
//! Simulator switched
void ps_simulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Cache changed
void ps_cacheChanged(BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Run the matcher
void ps_test();
//! Web data have been read
void ps_webDataRed(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
private:
//! Init
void redisplay();
//! Pseudo aircraft created from entries
BlackMisc::Simulation::CSimulatedAircraft createAircraft() const;
//! Pseudo default aircraft
BlackMisc::Simulation::CAircraftModel defaultModel() const;
QScopedPointer<Ui::CModelMatcherComponent> ui;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::Simulation::CAircraftMatcher m_matcher { BlackMisc::Simulation::CAircraftMatcher::All, this };
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,250 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CModelMatcherComponent</class>
<widget class="QFrame" name="CModelMatcherComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>324</width>
<height>318</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gl_ModelMatcher">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="1">
<widget class="BlackGui::Components::CDbAircraftIcaoSelectorComponent" name="comp_AircraftSelector">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="7" column="0" colspan="4">
<widget class="QFrame" name="fr_Results">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_Results" stretch="1,3">
<item>
<widget class="QTextEdit" name="te_Results">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::Views::CStatusMessageView" name="tvp_ResultMessages">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="3">
<widget class="BlackGui::Components::CDbLiverySelectorComponent" name="comp_LiverySelector">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="BlackGui::Components::CDbAirlineIcaoSelectorComponent" name="comp_AirlineSelector">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="BlackGui::Components::CAircraftCombinedTypeSelector" name="comp_CombinedCode">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_Model">
<property name="text">
<string>Model:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Aircraft">
<property name="text">
<string>Aircraft:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="lbl_Airline">
<property name="text">
<string>Airline:</string>
</property>
</widget>
</item>
<item row="5" column="1" colspan="3">
<widget class="QLineEdit" name="le_ModelString">
<property name="placeholderText">
<string>model string</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Simulator">
<property name="text">
<string>Simulator:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_Combined">
<property name="text">
<string>Combined:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="lbl_Livery">
<property name="text">
<string>Livery:</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QPushButton" name="pb_Test">
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="le_ModelSetCount">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="lbl_ModelSetCount">
<property name="text">
<string>Model set:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_Manufacturer">
<property name="text">
<string>Manufacturer:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_Manufacturer"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Components::CDbAirlineIcaoSelectorComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/dbairlineicaoselectorcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CDbLiverySelectorComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/dbliveryselectorcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CAircraftCombinedTypeSelector</class>
<extends>QFrame</extends>
<header>blackgui/components/aircraftcombinedtypeselector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CDbAircraftIcaoSelectorComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/dbaircrafticaoselectorcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CSimulatorSelector</class>
<extends>QFrame</extends>
<header>blackgui/components/simulatorselector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Views::CStatusMessageView</class>
<extends>QTableView</extends>
<header>blackgui/views/statusmessageview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>