swift
dbmodelkeycompleter.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "dbmodelkeycompleter.h"
5 
6 #include <QCompleter>
7 
8 #include "core/webdataservices.h"
9 #include "gui/guiapplication.h"
10 #include "gui/uppercasevalidator.h"
11 
12 using namespace swift::core;
13 using namespace swift::misc::simulation;
14 
15 namespace swift::gui::components
16 {
17  CDbModelKeyCompleter::CDbModelKeyCompleter(QWidget *parent) : QLineEdit(parent)
18  {
19  Q_ASSERT_X(sGui, Q_FUNC_INFO, "Need sGui");
20  Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "Need web services");
21 
22  this->setValidator(new CUpperCaseValidator(this));
23  this->initCompleter();
24  connect(sGui->getWebDataServices(), &CWebDataServices::swiftDbModelsRead, this,
25  &CDbModelKeyCompleter::onModelsRead);
26  }
27 
29  {
30  if (m_simulator == simulator) { return; }
31  m_simulator = simulator;
32  this->initCompleter();
33  }
34 
36  {
37  return sGui->getWebDataServices()->getModelForModelString(this->text().toUpper().trimmed());
38  }
39 
40  void CDbModelKeyCompleter::onModelsRead() { this->initCompleter(); }
41 
42  void CDbModelKeyCompleter::initCompleter()
43  {
44  const QStringList models(sGui->getWebDataServices()->getModelCompleterStrings(true, m_simulator));
45  if (models.isEmpty()) { return; }
46  this->setCompleter(new QCompleter(models, this));
47  }
48 } // namespace swift::gui::components
bool hasWebDataServices() const
Web data services available?
CWebDataServices * getWebDataServices() const
Get the web data services.
QStringList getModelCompleterStrings(bool sorted=true, const swift::misc::simulation::CSimulatorInfo &simulator={ swift::misc::simulation::CSimulatorInfo::All }) const
Model completer string.
swift::misc::simulation::CAircraftModel getModelForModelString(const QString &modelString) const
Model for model string if any.
void setSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Limit models to simulator, or add unspecified.
swift::misc::simulation::CAircraftModel getAircraftModel() const
Aircraft model for current string (searched in DB data)
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Simple hardcoded info about the corresponding simulator.
Definition: simulatorinfo.h:41
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.
Definition: actionbind.cpp:7
High level reusable GUI components.
Definition: aboutdialog.cpp:13