7 #include <QRadioButton>
8 #include <QStringListModel>
10 #include "ui_aircraftmodelstringcompleter.h"
18 using namespace swift::core::context;
19 using namespace swift::misc::simulation;
20 using namespace swift::misc::simulation::data;
24 CAircraftModelStringCompleter::CAircraftModelStringCompleter(QWidget *parent)
27 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"missing sGui");
33 connect(ui->le_modelString, &QLineEdit::editingFinished,
this, &CAircraftModelStringCompleter::onTextChanged);
35 &CAircraftModelStringCompleter::onSwiftModelDataRead);
36 connect(ui->rb_Db, &QRadioButton::clicked,
this, &CAircraftModelStringCompleter::initGui);
37 connect(ui->rb_ModelSet, &QRadioButton::clicked,
this, &CAircraftModelStringCompleter::initGui);
38 connect(ui->rb_OwnModels, &QRadioButton::clicked,
this, &CAircraftModelStringCompleter::initGui);
40 Qt::QueuedConnection);
46 &CAircraftModelStringCompleter::onSimulatorConnected, Qt::QueuedConnection);
66 if (ui->le_modelString->text() == completersString) {
return; }
67 ui->le_modelString->setText(completersString);
77 if (source.testFlag(DB)) { ui->rb_Db->setVisible(visible); }
78 if (source.testFlag(ModelSet)) { ui->rb_ModelSet->setVisible(visible); }
79 if (source.testFlag(OwnModels)) { ui->rb_OwnModels->setVisible(visible); }
86 case DB: ui->rb_Db->setChecked(
true);
break;
87 case ModelSet: ui->rb_ModelSet->setChecked(
true);
break;
88 case OwnModels: ui->rb_OwnModels->setChecked(
true);
break;
89 default: ui->rb_ModelSet->setChecked(
true);
break;
97 m_currentSimulator = simulator;
98 QPointer<CAircraftModelStringCompleter> myself(
this);
100 if (!myself) {
return; }
101 this->setCompleter(
true);
110 void CAircraftModelStringCompleter::setCompleter(
bool simChanged)
113 QStringList modelStrings;
115 QString simInfo = m_currentSimulator.
toQString();
116 if (ui->rb_Db->isChecked())
118 if (!simChanged && m_currentDataSource == DB) {
return; }
121 simInfo = QStringLiteral(
"DB models");
125 if (!simChanged && m_currentDataSource == ModelSet) {
return; }
127 dataSource = ModelSet;
129 else if (ui->rb_OwnModels->isChecked())
131 if (!simChanged && m_currentDataSource == OwnModels) {
return; }
133 dataSource = OwnModels;
136 m_currentDataSource = dataSource;
137 ui->le_modelString->setCompleter(
new QCompleter(modelStrings,
this));
138 ui->le_modelString->setPlaceholderText(
139 QStringLiteral(
"model strings (%1/%2)").arg(modelStrings.size()).arg(simInfo));
142 void CAircraftModelStringCompleter::onTextChanged() { emit this->
modelStringChanged(); }
144 void CAircraftModelStringCompleter::initGui() { this->setCompleter(
true); }
146 void CAircraftModelStringCompleter::onSimulatorConnected(
int status)
153 void CAircraftModelStringCompleter::onSwiftModelDataRead() { this->initGui(); }
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
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.
virtual swift::misc::simulation::CSimulatorPluginInfo getSimulatorPluginInfo() const =0
Simulator info, currently loaded plugin.
virtual QStringList getModelSetCompleterStrings(bool sorted) const =0
Model set completer string.
Completer for model strings.
void setSourceVisible(CompleterSource source, bool visible)
Show/hide radio buttons.
void showSourceSelection(bool show)
Show the selection buttons.
bool setSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Change the simulator.
void setModel(const swift::misc::simulation::CAircraftModel &model)
Set model.
void selectSource(CompleterSourceFlag source)
Set the currently selected source.
void setText(const QString &completersString)
Set text.
QString getModelString() const
The model string.
swift::misc::simulation::CSimulatorInfo getSimulator() const
Get current simulator.
CompleterSourceFlag
Sources for string completion.
@ None
normally used to indicate nothing was loaded
virtual ~CAircraftModelStringCompleter()
Destructor.
void modelStringChanged()
Model has been changed.
QString toQString(bool i18n=false) const
Cast as QString.
Aircraft model (used by another pilot, my models on disk)
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
QStringList toCompleterStrings(bool sorted=true, const CSimulatorInfo &simulator={ CSimulatorInfo::All }) const
Completer strings.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
const QString & getSimulator() const
Simulator.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Models for simulator.
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.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...