mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 08:36:52 +08:00
refs #443 Add simulator enable/disable option
* Added CPluginSelector widget * IContextSimulator starts/stops only specified listener(s) * No more "auto" CSimulatorPluginInfo
This commit is contained in:
committed by
Mathew Sutcliffe
parent
a4f0007414
commit
4d772050b0
@@ -39,13 +39,14 @@ namespace BlackGui
|
||||
Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "missing simulator");
|
||||
|
||||
// set values
|
||||
for (const auto &p : getAvailablePlugins(true))
|
||||
for (const auto &p : getAvailablePlugins())
|
||||
{
|
||||
ui->cb_Plugins->addItem(p.toQString(), QVariant::fromValue(p));
|
||||
ui->ps_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), false);
|
||||
}
|
||||
|
||||
// connects
|
||||
connect(this->ui->cb_Plugins, static_cast<void (QComboBox::*)(int)> (&QComboBox::currentIndexChanged), this, &CSettingsSimulatorComponent::ps_pluginHasBeenSelectedInComboBox);
|
||||
connect(this->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::ps_simulatorPluginChanged);
|
||||
connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::ps_pluginStateChanged);
|
||||
connect(this->ui->pb_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft);
|
||||
connect(this->ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyTimeSync);
|
||||
connect(this->ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance);
|
||||
@@ -58,29 +59,6 @@ namespace BlackGui
|
||||
this->ps_simulatorPluginChanged(getIContextSimulator()->getSimulatorPluginInfo());
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::setCurrentPluginInComboBox(const CSimulatorPluginInfo &plugin)
|
||||
{
|
||||
if (plugin.isUnspecified())
|
||||
{
|
||||
ui->cb_Plugins->setCurrentIndex(0);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < this->ui->cb_Plugins->count(); ++i)
|
||||
{
|
||||
QVariant data = this->ui->cb_Plugins->itemData(i);
|
||||
Q_ASSERT(data.canConvert<CSimulatorPluginInfo>());
|
||||
CSimulatorPluginInfo p = data.value<CSimulatorPluginInfo>();
|
||||
|
||||
if (p.getIdentifier() == plugin.getIdentifier())
|
||||
{
|
||||
if (i == this->ui->cb_Plugins->currentIndex()) { return; }
|
||||
this->ui->cb_Plugins->setCurrentIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::setGuiValues()
|
||||
{
|
||||
Q_ASSERT(getIContextSimulator());
|
||||
@@ -125,33 +103,37 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins(bool plusAuto) const
|
||||
CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins() const
|
||||
{
|
||||
CSimulatorPluginInfoList l(getIContextSimulator()->getAvailableSimulatorPlugins());
|
||||
if (plusAuto) { l.push_front(CSimulatorPluginInfo::autoPlugin()); }
|
||||
return l;
|
||||
return getIContextSimulator()->getAvailableSimulatorPlugins();
|
||||
}
|
||||
|
||||
void CSettingsSimulatorComponent::ps_pluginHasBeenSelectedInComboBox(int index)
|
||||
void CSettingsSimulatorComponent::ps_pluginStateChanged(const QString &identifier, bool enabled)
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
if (!this->getIContextSimulator()) { return; }
|
||||
Q_ASSERT(getIContextSimulator());
|
||||
|
||||
CSimulatorPluginInfoList simDrivers(getAvailablePlugins(true));
|
||||
if (simDrivers.isEmpty())
|
||||
CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
||||
auto selected = std::find_if(simDrivers.begin(), simDrivers.end(),
|
||||
[&identifier](const CSimulatorPluginInfo &info)
|
||||
{
|
||||
return info.getIdentifier() == identifier;
|
||||
});
|
||||
|
||||
if (selected->isUnspecified())
|
||||
{
|
||||
CLogMessage(this).error("No drivers available");
|
||||
return;
|
||||
}
|
||||
if (simDrivers.size() <= index)
|
||||
{
|
||||
CLogMessage(this).error("Wrong driver index");
|
||||
return;
|
||||
CLogMessage(this).error("Simulator plugin does not exist: %1") << identifier;
|
||||
}
|
||||
|
||||
// update
|
||||
CSimulatorPluginInfo selectedPlugin = simDrivers[index];
|
||||
this->getIContextSimulator()->startSimulatorPlugin(selectedPlugin);
|
||||
if (enabled)
|
||||
{
|
||||
getIContextSimulator()->startSimulatorPlugin(*selected);
|
||||
CLogMessage(this).info("Started listening for %1") << selected->getSimulator();
|
||||
}
|
||||
else
|
||||
{
|
||||
getIContextSimulator()->stopSimulatorPlugin(*selected);
|
||||
CLogMessage(this).info("Stopped listening for %1") << selected->getSimulator();
|
||||
}
|
||||
|
||||
// changing of GUI state will be done via received signal
|
||||
}
|
||||
|
||||
@@ -39,8 +39,9 @@ namespace BlackGui
|
||||
virtual void runtimeHasBeenSet() override;
|
||||
|
||||
private slots:
|
||||
//! Driver changed
|
||||
void ps_pluginHasBeenSelectedInComboBox(int index);
|
||||
//! Driver plugin enabled/disabled
|
||||
//! \todo Unload plugin if user disables it while running
|
||||
void ps_pluginStateChanged(const QString &identifier, bool enabled);
|
||||
|
||||
//! Apply max.aircraft
|
||||
void ps_onApplyMaxRenderedAircraft();
|
||||
@@ -62,14 +63,11 @@ namespace BlackGui
|
||||
|
||||
private:
|
||||
|
||||
//! Smarter way to set current driver, avoids unnecessary signals and less formatting dependend
|
||||
void setCurrentPluginInComboBox(const BlackMisc::Simulation::CSimulatorPluginInfo &plugin);
|
||||
|
||||
//! Set the GUI values
|
||||
void setGuiValues();
|
||||
|
||||
//! Available plugins, auto pseudo plugin added
|
||||
BlackMisc::Simulation::CSimulatorPluginInfoList getAvailablePlugins(bool plusAuto) const;
|
||||
BlackMisc::Simulation::CSimulatorPluginInfoList getAvailablePlugins() const;
|
||||
|
||||
QScopedPointer<Ui::CSettingsSimulatorComponent> ui; //!< UI
|
||||
bool m_pluginLoaded = false; //!< plugin loaded
|
||||
|
||||
@@ -53,26 +53,6 @@
|
||||
<property name="verticalSpacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Plugin">
|
||||
<property name="text">
|
||||
<string>Driver</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="cb_Plugins">
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QComboBox::AdjustToMinimumContentsLength</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_LoadedPlugin">
|
||||
<property name="text">
|
||||
@@ -380,6 +360,9 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="2">
|
||||
<widget class="BlackGui::CPluginSelector" name="ps_EnabledSimulators" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@@ -424,6 +407,12 @@
|
||||
<header>blackgui/led.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::CPluginSelector</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>blackgui/pluginselector.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
||||
Reference in New Issue
Block a user