mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +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
@@ -176,7 +176,6 @@ namespace BlackCore
|
|||||||
Q_ASSERT(c);
|
Q_ASSERT(c);
|
||||||
}
|
}
|
||||||
times.insert("Post setup, sim.connects", time.restart());
|
times.insert("Post setup, sim.connects", time.restart());
|
||||||
this->m_contextSimulator->startSimulatorPlugin(CSimulatorPluginInfo::autoPlugin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// only where network and(!) own aircraft run locally
|
// only where network and(!) own aircraft run locally
|
||||||
|
|||||||
@@ -99,8 +99,8 @@ namespace BlackCore
|
|||||||
//! Load and start specific simulator plugin
|
//! Load and start specific simulator plugin
|
||||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||||
|
|
||||||
//! Stop and unload simulator plugin and listeners
|
//! Stop listener or unload the given plugin (if currently loaded)
|
||||||
virtual void stopSimulatorPlugin() = 0;
|
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) = 0;
|
||||||
|
|
||||||
//! Simulator combined status
|
//! Simulator combined status
|
||||||
virtual int getSimulatorStatus() const = 0;
|
virtual int getSimulatorStatus() const = 0;
|
||||||
|
|||||||
@@ -50,12 +50,6 @@ namespace BlackCore
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
|
||||||
virtual void stopSimulatorPlugin() override
|
|
||||||
{
|
|
||||||
logEmptyContextWarning(Q_FUNC_INFO);
|
|
||||||
}
|
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||||
virtual int getSimulatorStatus() const override
|
virtual int getSimulatorStatus() const override
|
||||||
{
|
{
|
||||||
@@ -63,6 +57,13 @@ namespace BlackCore
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
||||||
|
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override
|
||||||
|
{
|
||||||
|
Q_UNUSED(simulatorInfo);
|
||||||
|
logEmptyContextWarning(Q_FUNC_INFO);
|
||||||
|
}
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::getAirportsInRange()
|
//! \copydoc IContextSimulator::getAirportsInRange()
|
||||||
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override
|
virtual BlackMisc::Aviation::CAirportList getAirportsInRange() const override
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace BlackCore
|
|||||||
void CContextSimulator::gracefulShutdown()
|
void CContextSimulator::gracefulShutdown()
|
||||||
{
|
{
|
||||||
this->disconnect();
|
this->disconnect();
|
||||||
this->stopSimulatorPlugin();
|
this->unloadSimulatorPlugin();
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
CSimulatorPluginInfoList CContextSimulator::getAvailableSimulatorPlugins() const
|
||||||
@@ -61,9 +61,15 @@ namespace BlackCore
|
|||||||
return this->loadSimulatorPlugin(simulatorInfo, true);
|
return this->loadSimulatorPlugin(simulatorInfo, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextSimulator::stopSimulatorPlugin()
|
void CContextSimulator::stopSimulatorPlugin(const CSimulatorPluginInfo &simulatorInfo)
|
||||||
{
|
{
|
||||||
this->unloadSimulatorPlugin();
|
if (!m_simulatorPlugin.first.isUnspecified() && m_simulatorPlugin.first == simulatorInfo)
|
||||||
|
{
|
||||||
|
this->unloadSimulatorPlugin();
|
||||||
|
}
|
||||||
|
|
||||||
|
ISimulatorListener *listener = m_plugins->getListener(simulatorInfo.getIdentifier());
|
||||||
|
QMetaObject::invokeMethod(listener, "stop");
|
||||||
}
|
}
|
||||||
|
|
||||||
int CContextSimulator::getSimulatorStatus() const
|
int CContextSimulator::getSimulatorStatus() const
|
||||||
@@ -281,28 +287,24 @@ namespace BlackCore
|
|||||||
Q_ASSERT(!simulatorInfo.isUnspecified());
|
Q_ASSERT(!simulatorInfo.isUnspecified());
|
||||||
Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread
|
Q_ASSERT(CThreadUtils::isCurrentThreadApplicationThread()); // only run in main thread
|
||||||
|
|
||||||
|
if (!simulatorInfo.isValid())
|
||||||
|
{
|
||||||
|
CLogMessage(this).error("Illegal plugin");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Is the plugin already loaded?
|
// Is the plugin already loaded?
|
||||||
if (!m_simulatorPlugin.first.isUnspecified() &&
|
if (!m_simulatorPlugin.first.isUnspecified())
|
||||||
(m_simulatorPlugin.first == simulatorInfo || simulatorInfo.isAuto()))
|
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
stopSimulatorListeners(); // we make sure all listeners are stopped and restart those we need
|
|
||||||
unloadSimulatorPlugin(); // old plugin unloaded
|
unloadSimulatorPlugin(); // old plugin unloaded
|
||||||
|
|
||||||
// now we have a state where no driver is loaded
|
// now we have a state where no driver is loaded
|
||||||
if (withListener)
|
if (withListener)
|
||||||
{
|
{
|
||||||
// hand over to listeners, when listener is done, it will call this function again
|
this->listenForSimulator(simulatorInfo);
|
||||||
if (simulatorInfo.isAuto())
|
|
||||||
{
|
|
||||||
this->listenForAllSimulators();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this->listenForSimulator(simulatorInfo);
|
|
||||||
}
|
|
||||||
return false; // not a plugin yet, just listener
|
return false; // not a plugin yet, just listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace BlackCore
|
|||||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
||||||
virtual void stopSimulatorPlugin() override;
|
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||||
virtual int getSimulatorStatus() const override;
|
virtual int getSimulatorStatus() const override;
|
||||||
@@ -171,9 +171,6 @@ namespace BlackCore
|
|||||||
//! Unload plugin, if desired restart listeners
|
//! Unload plugin, if desired restart listeners
|
||||||
void unloadSimulatorPlugin();
|
void unloadSimulatorPlugin();
|
||||||
|
|
||||||
//! Load plugin from settings
|
|
||||||
bool loadSimulatorPluginFromSettings();
|
|
||||||
|
|
||||||
//! Listen for single simulator
|
//! Listen for single simulator
|
||||||
void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo);
|
void listenForSimulator(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo);
|
||||||
|
|
||||||
|
|||||||
@@ -166,9 +166,9 @@ namespace BlackCore
|
|||||||
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("startSimulatorPlugin"), simulatorInfo);
|
return m_dBusInterface->callDBusRet<bool>(QLatin1Literal("startSimulatorPlugin"), simulatorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CContextSimulatorProxy::stopSimulatorPlugin()
|
void CContextSimulatorProxy::stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo)
|
||||||
{
|
{
|
||||||
m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"));
|
m_dBusInterface->callDBus(QLatin1Literal("stopSimulatorPlugin"), simulatorInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
CPixmap CContextSimulatorProxy::iconForModel(const QString &modelString) const
|
CPixmap CContextSimulatorProxy::iconForModel(const QString &modelString) const
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ namespace BlackCore
|
|||||||
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
virtual bool startSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
//! \copydoc IContextSimulator::stopSimulatorPlugin()
|
||||||
virtual void stopSimulatorPlugin() override;
|
virtual void stopSimulatorPlugin(const BlackMisc::Simulation::CSimulatorPluginInfo &simulatorInfo) override;
|
||||||
|
|
||||||
//! \copydoc IContextSimulator::getSimulatorStatus()
|
//! \copydoc IContextSimulator::getSimulatorStatus()
|
||||||
virtual int getSimulatorStatus() const override;
|
virtual int getSimulatorStatus() const override;
|
||||||
|
|||||||
@@ -39,13 +39,14 @@ namespace BlackGui
|
|||||||
Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "missing simulator");
|
Q_ASSERT_X(this->getIContextSimulator(), Q_FUNC_INFO, "missing simulator");
|
||||||
|
|
||||||
// set values
|
// 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
|
// 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_ApplyMaxAircraft, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedAircraft);
|
||||||
connect(this->ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyTimeSync);
|
connect(this->ui->pb_ApplyTimeSync, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyTimeSync);
|
||||||
connect(this->ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance);
|
connect(this->ui->pb_ApplyMaxDistance, &QCheckBox::pressed, this, &CSettingsSimulatorComponent::ps_onApplyMaxRenderedDistance);
|
||||||
@@ -58,29 +59,6 @@ namespace BlackGui
|
|||||||
this->ps_simulatorPluginChanged(getIContextSimulator()->getSimulatorPluginInfo());
|
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()
|
void CSettingsSimulatorComponent::setGuiValues()
|
||||||
{
|
{
|
||||||
Q_ASSERT(getIContextSimulator());
|
Q_ASSERT(getIContextSimulator());
|
||||||
@@ -125,33 +103,37 @@ namespace BlackGui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins(bool plusAuto) const
|
CSimulatorPluginInfoList CSettingsSimulatorComponent::getAvailablePlugins() const
|
||||||
{
|
{
|
||||||
CSimulatorPluginInfoList l(getIContextSimulator()->getAvailableSimulatorPlugins());
|
return getIContextSimulator()->getAvailableSimulatorPlugins();
|
||||||
if (plusAuto) { l.push_front(CSimulatorPluginInfo::autoPlugin()); }
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSettingsSimulatorComponent::ps_pluginHasBeenSelectedInComboBox(int index)
|
void CSettingsSimulatorComponent::ps_pluginStateChanged(const QString &identifier, bool enabled)
|
||||||
{
|
{
|
||||||
Q_ASSERT(this->getIContextSimulator());
|
Q_ASSERT(getIContextSimulator());
|
||||||
if (!this->getIContextSimulator()) { return; }
|
|
||||||
|
|
||||||
CSimulatorPluginInfoList simDrivers(getAvailablePlugins(true));
|
CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
|
||||||
if (simDrivers.isEmpty())
|
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");
|
CLogMessage(this).error("Simulator plugin does not exist: %1") << identifier;
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (simDrivers.size() <= index)
|
|
||||||
{
|
|
||||||
CLogMessage(this).error("Wrong driver index");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// update
|
if (enabled)
|
||||||
CSimulatorPluginInfo selectedPlugin = simDrivers[index];
|
{
|
||||||
this->getIContextSimulator()->startSimulatorPlugin(selectedPlugin);
|
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
|
// changing of GUI state will be done via received signal
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ namespace BlackGui
|
|||||||
virtual void runtimeHasBeenSet() override;
|
virtual void runtimeHasBeenSet() override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
//! Driver changed
|
//! Driver plugin enabled/disabled
|
||||||
void ps_pluginHasBeenSelectedInComboBox(int index);
|
//! \todo Unload plugin if user disables it while running
|
||||||
|
void ps_pluginStateChanged(const QString &identifier, bool enabled);
|
||||||
|
|
||||||
//! Apply max.aircraft
|
//! Apply max.aircraft
|
||||||
void ps_onApplyMaxRenderedAircraft();
|
void ps_onApplyMaxRenderedAircraft();
|
||||||
@@ -62,14 +63,11 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
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
|
//! Set the GUI values
|
||||||
void setGuiValues();
|
void setGuiValues();
|
||||||
|
|
||||||
//! Available plugins, auto pseudo plugin added
|
//! Available plugins, auto pseudo plugin added
|
||||||
BlackMisc::Simulation::CSimulatorPluginInfoList getAvailablePlugins(bool plusAuto) const;
|
BlackMisc::Simulation::CSimulatorPluginInfoList getAvailablePlugins() const;
|
||||||
|
|
||||||
QScopedPointer<Ui::CSettingsSimulatorComponent> ui; //!< UI
|
QScopedPointer<Ui::CSettingsSimulatorComponent> ui; //!< UI
|
||||||
bool m_pluginLoaded = false; //!< plugin loaded
|
bool m_pluginLoaded = false; //!< plugin loaded
|
||||||
|
|||||||
@@ -53,26 +53,6 @@
|
|||||||
<property name="verticalSpacing">
|
<property name="verticalSpacing">
|
||||||
<number>6</number>
|
<number>6</number>
|
||||||
</property>
|
</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">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="lbl_LoadedPlugin">
|
<widget class="QLabel" name="lbl_LoadedPlugin">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@@ -380,6 +360,9 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="BlackGui::CPluginSelector" name="ps_EnabledSimulators" native="true"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -424,6 +407,12 @@
|
|||||||
<header>blackgui/led.h</header>
|
<header>blackgui/led.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
|
<customwidget>
|
||||||
|
<class>BlackGui::CPluginSelector</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>blackgui/pluginselector.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
|
|||||||
67
src/blackgui/pluginselector.cpp
Normal file
67
src/blackgui/pluginselector.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include "pluginselector.h"
|
||||||
|
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
CPluginSelector::CPluginSelector(QWidget *parent) : QWidget(parent)
|
||||||
|
{
|
||||||
|
setObjectName("CPluginSelector");
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
|
setLayout(layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginSelector::addPlugin(const QString& identifier, const QString &name, bool enabled)
|
||||||
|
{
|
||||||
|
QWidget *pw = new QWidget;
|
||||||
|
QHBoxLayout *layout = new QHBoxLayout;
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
pw->setLayout(layout);
|
||||||
|
|
||||||
|
QCheckBox *cb = new QCheckBox(name);
|
||||||
|
cb->setProperty("pluginIdentifier", identifier);
|
||||||
|
connect(cb, &QCheckBox::stateChanged, this, &CPluginSelector::ps_handlePluginStateChange);
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
cb->setCheckState(Qt::Checked);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cb->setCheckState(Qt::Unchecked);
|
||||||
|
}
|
||||||
|
|
||||||
|
pw->layout()->addWidget(cb);
|
||||||
|
|
||||||
|
/* Might be useful for #392 */
|
||||||
|
#if 0
|
||||||
|
QPushButton *pb = new QPushButton("...");
|
||||||
|
pw->layout()->addWidget(pb);
|
||||||
|
|
||||||
|
layout->setStretch(0, 1);
|
||||||
|
layout->setStretch(1, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
this->layout()->addWidget(pw);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CPluginSelector::ps_handlePluginStateChange()
|
||||||
|
{
|
||||||
|
QCheckBox *cb = qobject_cast<QCheckBox*>(sender());
|
||||||
|
Q_ASSERT(cb);
|
||||||
|
|
||||||
|
bool enabled = cb->checkState() != Qt::Unchecked;
|
||||||
|
Q_ASSERT(cb->property("pluginIdentifier").isValid());
|
||||||
|
QString identifier = cb->property("pluginIdentifier").toString();
|
||||||
|
Q_ASSERT(!identifier.isEmpty());
|
||||||
|
|
||||||
|
emit pluginStateChanged(identifier, enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace
|
||||||
50
src/blackgui/pluginselector.h
Normal file
50
src/blackgui/pluginselector.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright (C) 2014
|
||||||
|
* swift project Community / Contributors
|
||||||
|
*
|
||||||
|
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||||
|
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||||
|
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||||
|
* contained in the LICENSE file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef PLUGINSELECTOR_H
|
||||||
|
#define PLUGINSELECTOR_H
|
||||||
|
|
||||||
|
#include "blackgui/blackguiexport.h"
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
namespace BlackGui {
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief The CPluginSelector class is used to select which plugins are to be loaded
|
||||||
|
* and (optionally) configure them.
|
||||||
|
*/
|
||||||
|
class BLACKGUI_EXPORT CPluginSelector : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
signals:
|
||||||
|
//! Emitted when user enables/disables the particular plugin
|
||||||
|
void pluginStateChanged(QString identifier, bool enabled);
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
explicit CPluginSelector(QWidget *parent = 0);
|
||||||
|
|
||||||
|
//! Adds the new plugin to the list.
|
||||||
|
//! \param identifier Identifier of the plugin.
|
||||||
|
//! \param name Name of the plugin
|
||||||
|
//! \param enabled Defines whether the plugin is initially enabled or not
|
||||||
|
void addPlugin(const QString &identifier, const QString &name, bool enabled = true);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void ps_handlePluginStateChange();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace BlackGui
|
||||||
|
|
||||||
|
#endif // PLUGINSELECTOR_H
|
||||||
@@ -39,21 +39,11 @@ namespace BlackMisc
|
|||||||
return m_identifier.isEmpty();
|
return m_identifier.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSimulatorPluginInfo::isAuto() const
|
|
||||||
{
|
|
||||||
return (*this) == autoPlugin();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString CSimulatorPluginInfo::convertToQString(bool i18n) const
|
QString CSimulatorPluginInfo::convertToQString(bool i18n) const
|
||||||
{
|
{
|
||||||
Q_UNUSED(i18n);
|
Q_UNUSED(i18n);
|
||||||
return QString("%1 (%2)").arg(m_name, m_identifier);
|
return QString("%1 (%2)").arg(m_name, m_identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
const CSimulatorPluginInfo &CSimulatorPluginInfo::autoPlugin()
|
|
||||||
{
|
|
||||||
static const CSimulatorPluginInfo p("auto", "auto", "auto", "automatic plugin selection", false);
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -56,15 +56,9 @@ namespace BlackMisc
|
|||||||
//! Description
|
//! Description
|
||||||
const QString &getDescription() const { return m_description; }
|
const QString &getDescription() const { return m_description; }
|
||||||
|
|
||||||
//! Special info of type auto?
|
|
||||||
bool isAuto() const;
|
|
||||||
|
|
||||||
//! \copydoc CValueObject::convertToQString
|
//! \copydoc CValueObject::convertToQString
|
||||||
QString convertToQString(bool i18n = false) const;
|
QString convertToQString(bool i18n = false) const;
|
||||||
|
|
||||||
//! Info representing a entry representing automatic plugin selection
|
|
||||||
static const CSimulatorPluginInfo &autoPlugin();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorPluginInfo)
|
BLACK_ENABLE_TUPLE_CONVERSION(CSimulatorPluginInfo)
|
||||||
QString m_identifier;
|
QString m_identifier;
|
||||||
|
|||||||
Reference in New Issue
Block a user