mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #917, use utility functions in simulator settings
This commit is contained in:
committed by
Mathew Sutcliffe
parent
0544ab0193
commit
f816c927ee
@@ -148,29 +148,24 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
Q_ASSERT(sGui->getIContextSimulator());
|
Q_ASSERT(sGui->getIContextSimulator());
|
||||||
|
|
||||||
CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
const CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
||||||
auto selected = std::find_if(simDrivers.begin(), simDrivers.end(),
|
const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier);
|
||||||
[&identifier](const CSimulatorPluginInfo & info)
|
if (selected.isUnspecified())
|
||||||
{
|
|
||||||
return info.getIdentifier() == identifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (selected == simDrivers.end() || selected->isUnspecified())
|
|
||||||
{
|
{
|
||||||
CLogMessage(this).error("Simulator plugin does not exist: '%1'") << identifier;
|
CLogMessage(this).error("Simulator plugin does not exist: '%1'") << identifier;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto e = m_enabledSimulators.getThreadLocal();
|
QStringList e = m_enabledSimulators.getThreadLocal();
|
||||||
if (enabled != e.contains(selected->getIdentifier()))
|
if (enabled != e.contains(selected.getIdentifier()))
|
||||||
{
|
{
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
e << selected->getIdentifier();
|
e << selected.getIdentifier();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
e.removeAll(selected->getIdentifier());
|
e.removeAll(selected.getIdentifier());
|
||||||
}
|
}
|
||||||
m_enabledSimulators.set(e);
|
m_enabledSimulators.set(e);
|
||||||
}
|
}
|
||||||
@@ -182,7 +177,7 @@ namespace BlackGui
|
|||||||
{
|
{
|
||||||
// get initial aircraft to render
|
// get initial aircraft to render
|
||||||
CInterpolationAndRenderingSetup setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetup();
|
CInterpolationAndRenderingSetup setup = sGui->getIContextSimulator()->getInterpolationAndRenderingSetup();
|
||||||
int noRequested = ui->le_MaxAircraft->text().isEmpty() ? setup.InfiniteAircraft() : ui->le_MaxAircraft->text().toInt();
|
const int noRequested = ui->le_MaxAircraft->text().isEmpty() ? setup.InfiniteAircraft() : ui->le_MaxAircraft->text().toInt();
|
||||||
const int oldValue = setup.getMaxRenderedAircraft();
|
const int oldValue = setup.getMaxRenderedAircraft();
|
||||||
if (oldValue == noRequested) { return; }
|
if (oldValue == noRequested) { return; }
|
||||||
|
|
||||||
@@ -286,34 +281,25 @@ namespace BlackGui
|
|||||||
void CSettingsSimulatorComponent::ps_showPluginDetails(const QString &identifier)
|
void CSettingsSimulatorComponent::ps_showPluginDetails(const QString &identifier)
|
||||||
{
|
{
|
||||||
const CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
const CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
||||||
const auto selected = std::find_if(
|
const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier);
|
||||||
simDrivers.begin(), simDrivers.end(),
|
|
||||||
[&identifier](const CSimulatorPluginInfo & info)
|
|
||||||
{
|
|
||||||
return info.getIdentifier() == identifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
QWidget *aw = qApp->activeWindow();
|
QWidget *aw = qApp->activeWindow();
|
||||||
|
|
||||||
CPluginDetailsWindow *w = new CPluginDetailsWindow(aw);
|
CPluginDetailsWindow *w = new CPluginDetailsWindow(aw);
|
||||||
w->setAttribute(Qt::WA_DeleteOnClose);
|
w->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
w->setPluginIdentifier(selected->getIdentifier());
|
w->setPluginIdentifier(selected.getIdentifier());
|
||||||
w->setPluginName(selected->getName());
|
w->setPluginName(selected.getName());
|
||||||
w->setPluginDescription(selected->getDescription());
|
w->setPluginDescription(selected.getDescription());
|
||||||
|
|
||||||
w->show();
|
w->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettingsSimulatorComponent::ps_showPluginConfig(const QString &identifier)
|
void CSettingsSimulatorComponent::ps_showPluginConfig(const QString &identifier)
|
||||||
{
|
{
|
||||||
CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
const CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
||||||
const auto selected = std::find_if(simDrivers.begin(), simDrivers.end(),
|
const CSimulatorPluginInfo selected = simDrivers.findByIdentifier(identifier);
|
||||||
[&identifier](const CSimulatorPluginInfo & info)
|
|
||||||
{
|
|
||||||
return info.getIdentifier() == identifier;
|
|
||||||
});
|
|
||||||
|
|
||||||
const QString configId = m_plugins->getPluginConfigId(selected->getIdentifier());
|
const QString configId = m_plugins->getPluginConfigId(selected.getIdentifier());
|
||||||
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
|
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
|
||||||
if (!config)
|
if (!config)
|
||||||
{
|
{
|
||||||
@@ -328,7 +314,7 @@ namespace BlackGui
|
|||||||
void CSettingsSimulatorComponent::ps_reloadPluginConfig()
|
void CSettingsSimulatorComponent::ps_reloadPluginConfig()
|
||||||
{
|
{
|
||||||
// list all available simulators
|
// list all available simulators
|
||||||
auto enabledSimulators = m_enabledSimulators.getThreadLocal();
|
const auto enabledSimulators = m_enabledSimulators.getThreadLocal();
|
||||||
for (const auto &p : getAvailablePlugins())
|
for (const auto &p : getAvailablePlugins())
|
||||||
{
|
{
|
||||||
ui->pluginSelector_EnabledSimulators->setEnabled(p.getIdentifier(), enabledSimulators.contains(p.getIdentifier()));
|
ui->pluginSelector_EnabledSimulators->setEnabled(p.getIdentifier(), enabledSimulators.contains(p.getIdentifier()));
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace Simulation
|
namespace Simulation
|
||||||
{
|
{
|
||||||
|
|
||||||
CSimulatorPluginInfoList::CSimulatorPluginInfoList() { }
|
CSimulatorPluginInfoList::CSimulatorPluginInfoList() { }
|
||||||
|
|
||||||
bool CSimulatorPluginInfoList::supportsSimulator(const QString &simulator) const
|
bool CSimulatorPluginInfoList::supportsSimulator(const QString &simulator) const
|
||||||
@@ -35,5 +34,9 @@ namespace BlackMisc
|
|||||||
return this->transform([i18n](const CSimulatorPluginInfo & info) { return info.toQString(i18n); });
|
return this->transform([i18n](const CSimulatorPluginInfo & info) { return info.toQString(i18n); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CSimulatorPluginInfo CSimulatorPluginInfoList::findByIdentifier(const QString &identifier) const
|
||||||
|
{
|
||||||
|
return this->findFirstByOrDefault(&CSimulatorPluginInfo::getIdentifier, identifier);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ namespace BlackMisc
|
|||||||
//! String list with meaningful representations
|
//! String list with meaningful representations
|
||||||
QStringList toStringList(bool i18n = false) const;
|
QStringList toStringList(bool i18n = false) const;
|
||||||
|
|
||||||
|
//! Find by identifier (unique)
|
||||||
|
CSimulatorPluginInfo findByIdentifier(const QString &identifier) const;
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user