mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Fixes completer (model strings), show correct placeholder when simulator is changed
This commit is contained in:
@@ -155,7 +155,7 @@ namespace BlackCore
|
||||
virtual BlackMisc::Simulation::CSimulatorInfo getModelSetLoaderSimulator() const = 0;
|
||||
|
||||
//! Set the model set loader simulator directly
|
||||
//! \note for testing purposes
|
||||
//! \note for testing purposes and can be used if no simulator is connected
|
||||
virtual void setModelSetLoaderSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
|
||||
|
||||
//! Simulators which have an initialized model set
|
||||
|
||||
@@ -40,11 +40,13 @@ namespace BlackGui
|
||||
connect(ui->rb_Db, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::initGui);
|
||||
connect(ui->rb_ModelSet, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::initGui);
|
||||
connect(ui->rb_OwnModels, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::initGui);
|
||||
connect(&m_modelCaches, &CModelCaches::cacheChanged, this, &CAircraftModelStringCompleter::setSimulator, Qt::QueuedConnection);
|
||||
|
||||
CSimulatorInfo sim = CSimulatorInfo(CSimulatorInfo::P3D); // default
|
||||
if (sGui->getIContextSimulator())
|
||||
{
|
||||
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CAircraftModelStringCompleter::onSimulatorConnected);
|
||||
const CSimulatorInfo sim(sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator());
|
||||
sim = sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator();
|
||||
if (sim.isSingleSimulator())
|
||||
{
|
||||
m_modelCaches.setCurrentSimulator(sim);
|
||||
@@ -52,8 +54,10 @@ namespace BlackGui
|
||||
else
|
||||
{
|
||||
this->setSourceVisible(OwnModels, false);
|
||||
sim = m_modelCaches.getCurrentSimulator();
|
||||
}
|
||||
}
|
||||
this->setSimulator(sim);
|
||||
}
|
||||
|
||||
CAircraftModelStringCompleter::~CAircraftModelStringCompleter()
|
||||
@@ -98,37 +102,53 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
bool CAircraftModelStringCompleter::setSimulator(const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (this->getSimulator() == simulator) { return false; }
|
||||
m_currentSimulator = simulator;
|
||||
m_modelCaches.setCurrentSimulator(simulator); // all models
|
||||
QTimer::singleShot(100, this, [ = ] { this->setCompleter(true); });
|
||||
return true;
|
||||
}
|
||||
|
||||
CSimulatorInfo CAircraftModelStringCompleter::getSimulator() const
|
||||
{
|
||||
return m_currentSimulator;
|
||||
}
|
||||
|
||||
void CAircraftModelStringCompleter::clear()
|
||||
{
|
||||
ui->le_modelString->clear();
|
||||
}
|
||||
|
||||
void CAircraftModelStringCompleter::setCompleter()
|
||||
void CAircraftModelStringCompleter::setCompleter(bool simChanged)
|
||||
{
|
||||
QStringList modelStrings;
|
||||
CompleterSourceFlag sourceWithData = None;
|
||||
CompleterSourceFlag dataSource = None;
|
||||
QString simInfo = m_currentSimulator.toQString();
|
||||
if (ui->rb_Db->isChecked())
|
||||
{
|
||||
if (m_currentSourceWithData == DB) { return; }
|
||||
if (!simChanged && m_currentDataSource == DB) { return; }
|
||||
modelStrings = sGui->getWebDataServices()->getModelCompleterStrings();
|
||||
if (!modelStrings.isEmpty()) { sourceWithData = DB; }
|
||||
dataSource = DB;
|
||||
simInfo = QStringLiteral("DB models");
|
||||
}
|
||||
else if (ui->rb_ModelSet->isChecked())
|
||||
{
|
||||
if (m_currentSourceWithData == ModelSet) { return; }
|
||||
if (!simChanged && m_currentDataSource == ModelSet) { return; }
|
||||
modelStrings = sGui->getIContextSimulator()->getModelSetCompleterStrings(true);
|
||||
if (!modelStrings.isEmpty()) { sourceWithData = ModelSet; }
|
||||
dataSource = ModelSet;
|
||||
}
|
||||
else if (ui->rb_OwnModels->isChecked())
|
||||
{
|
||||
if (m_currentSourceWithData == OwnModels) { return; }
|
||||
if (!simChanged && m_currentDataSource == OwnModels) { return; }
|
||||
modelStrings = m_modelCaches.getCurrentCachedModels().toCompleterStrings();
|
||||
if (!modelStrings.isEmpty()) { sourceWithData = OwnModels; }
|
||||
dataSource = OwnModels;
|
||||
}
|
||||
|
||||
m_currentSourceWithData = sourceWithData;
|
||||
m_currentDataSource = dataSource;
|
||||
ui->le_modelString->setCompleter(new QCompleter(modelStrings, this));
|
||||
ui->le_modelString->setPlaceholderText(QString("model strings (%1)").arg(modelStrings.size()));
|
||||
ui->le_modelString->setPlaceholderText(QString("model strings (%1/%2)").arg(modelStrings.size()).arg(simInfo));
|
||||
}
|
||||
|
||||
void CAircraftModelStringCompleter::onTextChanged()
|
||||
@@ -138,7 +158,7 @@ namespace BlackGui
|
||||
|
||||
void CAircraftModelStringCompleter::initGui()
|
||||
{
|
||||
this->setCompleter();
|
||||
this->setCompleter(true);
|
||||
}
|
||||
|
||||
void CAircraftModelStringCompleter::onSimulatorConnected(int status)
|
||||
|
||||
@@ -67,6 +67,12 @@ namespace BlackGui
|
||||
//! Set the currently selected source
|
||||
void selectSource(CompleterSourceFlag source);
|
||||
|
||||
//! Change the simulator
|
||||
bool setSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Get current simulator
|
||||
BlackMisc::Simulation::CSimulatorInfo getSimulator() const;
|
||||
|
||||
//! Clear
|
||||
void clear();
|
||||
|
||||
@@ -76,7 +82,7 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
//! Set the completer
|
||||
void setCompleter();
|
||||
void setCompleter(bool simChanged);
|
||||
|
||||
//! Init the GUI
|
||||
void initGui();
|
||||
@@ -92,8 +98,10 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
QScopedPointer <Ui::CAircraftModelStringCompleter> ui;
|
||||
// model set completer data are fetched from context
|
||||
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this }; //!< all models, works locally only
|
||||
CompleterSourceFlag m_currentSourceWithData = None;
|
||||
BlackMisc::Simulation::CSimulatorInfo m_currentSimulator;
|
||||
CompleterSourceFlag m_currentDataSource = None;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -56,6 +56,12 @@ namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
const CLogCategoryList &CMappingComponent::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats({ CLogCategory::mapping(), CLogCategory::guiComponent() });
|
||||
return cats;
|
||||
}
|
||||
|
||||
CMappingComponent::CMappingComponent(QWidget *parent) :
|
||||
COverlayMessagesFrame(parent),
|
||||
CIdentifiable(this),
|
||||
@@ -137,18 +143,13 @@ namespace BlackGui
|
||||
connect(ui->tvp_RenderedAircraft, &CAircraftModelView::objectChanged, this, &CMappingComponent::onChangedSimulatedAircraftInView);
|
||||
|
||||
// with external core models might be already available
|
||||
this->onModelSetSimulatorChanged(ui->comp_SimulatorSelector->getValue());
|
||||
this->onModelSetChanged();
|
||||
}
|
||||
|
||||
CMappingComponent::~CMappingComponent()
|
||||
{ }
|
||||
|
||||
const CLogCategoryList &CMappingComponent::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats({ CLogCategory::mapping(), CLogCategory::guiComponent() });
|
||||
return cats;
|
||||
}
|
||||
|
||||
int CMappingComponent::countCurrentMappings() const
|
||||
{
|
||||
Q_ASSERT(ui->tvp_RenderedAircraft);
|
||||
@@ -177,6 +178,9 @@ namespace BlackGui
|
||||
{
|
||||
CLogMessage(this).info("Models loaded, you can update the model view");
|
||||
}
|
||||
|
||||
// change completer
|
||||
ui->completer_ModelStrings->setSimulator(ui->comp_SimulatorSelector->getValue());
|
||||
}
|
||||
|
||||
void CMappingComponent::onRowCountChanged(int count, bool withFilter)
|
||||
@@ -287,8 +291,11 @@ namespace BlackGui
|
||||
void CMappingComponent::onModelSetSimulatorChanged(const CSimulatorInfo &simulator)
|
||||
{
|
||||
if (!sGui || !sGui->supportsContexts()) { return; }
|
||||
if (sGui->isShuttingDown()) { return; }
|
||||
if (sGui->getIContextSimulator()->isSimulatorAvailable()) { return; }
|
||||
sGui->getIContextSimulator()->setModelSetLoaderSimulator(simulator);
|
||||
|
||||
// completer will be changed in onModelSetChanged
|
||||
}
|
||||
|
||||
void CMappingComponent::onPluginChanged(const CSimulatorPluginInfo &pluginInfo)
|
||||
|
||||
Reference in New Issue
Block a user