10 #include <QStringBuilder>
11 #include <QStringList>
16 #include "ui_modelmatchercomponent.h"
41 using namespace swift::misc::aviation;
42 using namespace swift::misc::simulation;
43 using namespace swift::misc::simulation::data;
44 using namespace swift::misc::network;
53 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
58 ui->comp_SimulatorSelector->setRememberSelectionAndSetToLastSelection();
59 ui->comp_AirlineSelector->displayWithIcaoDescription(
false);
60 ui->comp_AircraftSelector->displayWithIcaoDescription(
false);
61 ui->comp_LiverySelector->withLiveryDescription(
false);
62 ui->tvp_ResultMessages->setMode(CStatusMessageListModel::Simplified);
63 ui->tvp_ResultMessages->menuAddItems(CViewBaseNonTemplate::MenuSave);
66 ui->le_ModelString->setValidator(validator);
67 ui->le_Manufacturer->setValidator(validator);
68 ui->le_Callsign->setValidator(validator);
71 &CModelMatcherComponent::onSimulatorChanged);
72 connect(
sGui->
getWebDataServices(), &CWebDataServices::dataRead,
this, &CModelMatcherComponent::onWebDataRead,
73 Qt::QueuedConnection);
75 connect(ui->pb_ModelMatching, &QPushButton::pressed,
this, &CModelMatcherComponent::testModelMatching);
76 connect(ui->pb_ReverseLookup, &QPushButton::pressed,
this, &CModelMatcherComponent::reverseLookup);
77 connect(ui->pb_Settings, &QPushButton::pressed,
this, &CModelMatcherComponent::displaySettingsDialog);
79 connect(ui->cb_UseWorkbench, &QCheckBox::toggled,
this, &CModelMatcherComponent::onWorkbenchToggled);
85 ui->cb_UseWorkbench->setVisible(
false);
92 if (index < 0) {
return; }
94 Q_ASSERT_X(tw, Q_FUNC_INFO,
"Cannot find parent tab widget");
95 const QWidget *tabWidget = tw->currentWidget();
96 const QWidget *myselfTabWidget = this->parentWidget();
97 if (tabWidget != myselfTabWidget) {
return; }
105 ui->cb_UseWorkbench->setVisible(
true);
106 m_workbenchView = workbenchView;
110 ui->cb_UseWorkbench->setVisible(
false);
111 m_workbenchView.clear();
115 void CModelMatcherComponent::onSimulatorChanged(
const CSimulatorInfo &simulator)
119 ui->tvp_ResultMessages->clear();
120 if (this->useWorkbench())
125 CStatusMessage m(
this, CStatusMessage::SeverityWarning, u
"No models in workbench, disabled.");
126 ui->tvp_ResultMessages->insert(m);
135 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(simulator);
141 void CModelMatcherComponent::onWorkbenchToggled(
bool checked)
144 this->onSimulatorChanged(ui->comp_SimulatorSelector->getValue());
147 void CModelMatcherComponent::onCacheChanged(
const CSimulatorInfo &simulator)
153 void CModelMatcherComponent::testModelMatching()
155 ui->te_Results->clear();
156 this->onSimulatorChanged(ui->comp_SimulatorSelector->getValue());
161 if (ui->cb_withReverseLookup->isChecked())
163 const QString liveryString(ui->comp_LiverySelector->getRawCombinedCode());
167 CAircraftMatcher::reverseLookupModelMs(remoteAircraft.getModel(), liveryString, setup, modelSet, &msgs);
168 remoteAircraft.setModel(reverseModel);
173 m_matcher.
getClosestMatch(remoteAircraft, MatchingLogAll, &matchingMsgs,
true);
176 ui->te_Results->setText(matched.
toQString(
true));
177 ui->tvp_ResultMessages->updateContainer(msgs);
178 ui->tvp_ResultMessages->fullResizeToContents();
179 ui->tvp_ResultMessages->resizeRowsToContents();
182 void CModelMatcherComponent::reverseLookup()
186 ui->te_Results->clear();
193 const QString livery(ui->comp_LiverySelector->getRawCombinedCode());
195 CAircraftMatcher::reverseLookupModelMs(remoteAircraft.getModel(), livery, setup, modelSet, &msgs);
196 ui->te_Results->setText(matched.
toQString(
true));
197 ui->tvp_ResultMessages->updateContainer(msgs);
200 void CModelMatcherComponent::onWebDataRead(CEntityFlags::Entity entity,
CEntityFlags::ReadState state,
int number,
206 if (number > 0 && entity.testFlag(CEntityFlags::ModelEntity) && CEntityFlags::isFinishedReadState(state))
209 ui->le_ModelString->setCompleter(
new QCompleter(modelStrings,
this));
213 void CModelMatcherComponent::displaySettingsDialog()
215 if (!m_settingsDialog) { m_settingsDialog =
new CSettingsMatchingDialog(
this); }
217 const QDialog::DialogCode r =
static_cast<QDialog::DialogCode
>(m_settingsDialog->exec());
221 void CModelMatcherComponent::redisplay()
223 const int c = this->getMatcherModelsCount();
224 ui->le_ModelSetCount->setText(QString::number(c) % (this->useWorkbench() ? u
" (workbench)" : u
""));
229 const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
231 CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(simulator);
235 int CModelMatcherComponent::getMatcherModelsCount()
const {
return m_matcher.
getModelSetCount(); }
237 bool CModelMatcherComponent::useWorkbench()
const {
return ui->cb_UseWorkbench->isChecked() && m_workbenchView; }
241 const QString airline(ui->comp_AirlineSelector->getRawDesignator());
242 const QString aircraft(ui->comp_AircraftSelector->getRawDesignator());
243 const QString modelString(ui->le_ModelString->text().trimmed().toUpper());
244 const QString combined(ui->comp_CombinedCode->getCombinedType());
245 const QString manufacturer(ui->le_Manufacturer->text().trimmed().toUpper());
246 const QString liveryCombinedCode(ui->comp_LiverySelector->getRawCombinedCode());
247 const CCallsign cs(ui->le_Callsign->text().isEmpty() ?
"SWIFT" : ui->le_Callsign->text());
248 static const CUser pilot(
"123456",
"swift Test", cs);
251 icao.setManufacturer(manufacturer);
254 const CLivery livery(liveryCombinedCode, airlineIcao,
"");
258 m.setModelType(modelString.isEmpty() ? CAircraftModel::TypeQueriedFromNetwork : CAircraftModel::TypeFSInnData);
261 sa.setAircraftIcaoCode(icao);
268 const CAircraftIcaoCode icaoAircraft(
"B737",
"L2J",
"FooBar",
"Dummy", CWakeTurbulenceCategory::MEDIUM,
false,
270 const CAirlineIcaoCode icaoAirline(
"Foo",
"FooBar airlines", {
"DE",
"Germany" },
"FOO",
true,
true);
271 const CLivery livery(CLivery::getStandardCode(icaoAirline), icaoAirline,
"Standard Foo airlines",
"red",
"blue",
273 CAircraftModel model(
"default model", CAircraftModel::TypeOwnSimulatorModel,
"dummy model", icaoAircraft,
275 if (model.getCallsign().isEmpty()) { model.setCallsign(
"SWIFT"); }
288 CAircraftMatcher::reverseLookupScript(inModel, setup, modelSet, &msgs);
292 CCallsign::addLogDetailsToList(&msgs, inModel.
getCallsign(),
293 QStringLiteral(
"Matching script, no modification"));
298 CCallsign::addLogDetailsToList(&msgs, inModel.
getCallsign(),
299 QStringLiteral(
"No reverse lookup script used"));
void setDefaultModel(const swift::misc::simulation::CAircraftModel &defaultModel)
Set default model, can be set by driver specific for simulator.
swift::misc::simulation::CAircraftMatcherSetup getSetup() const
Get the setup.
virtual int getModelSetCount() const
Model set count.
int setModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator, bool forced)
Set the models we want to use.
bool setSetup(const swift::misc::simulation::CAircraftMatcherSetup &setup)
Set the setup.
swift::misc::simulation::CAircraftModel getClosestMatch(const swift::misc::simulation::CSimulatedAircraft &remoteAircraft, swift::misc::simulation::MatchingLog whatToLog, swift::misc::CStatusMessageList *log, bool useMatchingScript) const
Get the closest matching aircraft model from set. Result depends on setup.
virtual swift::misc::simulation::CAircraftModelList getModelSet() const
Get the model set models.
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
QStringList getModelStrings(bool sort=false) const
Model strings.
static QTabWidget * parentTabWidget(QWidget *widget, int maxLevels=5)
From a given widget try to find parent tab widget (where widget is embedded)
Model matcher testing and configuration.
void setWorkbenchView(views::CAircraftModelView *workbenchView)
Set an external.
virtual ~CModelMatcherComponent()
Destructor.
void tabIndexChanged(int index)
Tab (where this component is embedded) has been changed.
swift::misc::simulation::CAircraftMatcherSetup getMatchingSetup() const
Get setup.
void setMatchingSetup(const swift::misc::simulation::CAircraftMatcherSetup &setup)
Set the setup.
void changed(const swift::misc::simulation::CSimulatorInfo &simulator)
Value has been changed.
T get() const
Get a copy of the current value.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Value object for ICAO classification.
Value object for ICAO classification.
Value object encapsulating information of a callsign.
Value object encapsulating information about an airpot.
QString toQString(bool i18n=false) const
Cast as QString.
ReadState
State of operation.
Value object encapsulating information of a user.
bool doRunMsReverseLookupScript() const
Run the scripts.
Aircraft model (used by another pilot, my models on disk)
const aviation::CCallsign & getCallsign() const
Corresponding callsign if applicable.
Value object encapsulating a list of aircraft models.
CSimulatorInfo simulatorsWithMaxEntries() const
Which simulator(s) have the most entries?
Comprehensive information of an aircraft.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
bool runScriptAndModified() const
Did run the script with modified result.