refs #392 Added BlackGui::IPluginConfig

* BlackGui::IPluginConfig is an interface for plugin configurations
* Added plugin_xplane_config target
* Adapted IPluginManager
* Adapted CPluginManagerSimulator
* Adaptem CSettingsSimulatorComponent
This commit is contained in:
Michał Garapich
2015-09-02 00:54:06 +02:00
committed by Mathew Sutcliffe
parent 584616de7a
commit a0b4d47736
21 changed files with 356 additions and 51 deletions

View File

@@ -1,7 +1,6 @@
load(common_pre)
QT += network dbus gui svg
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
QT += network dbus gui svg widgets
TARGET = blackgui
TEMPLATE = lib

View File

@@ -3,6 +3,7 @@
#include "blackcore/context_simulator.h"
#include "blackcore/context_network.h"
#include "blackgui/pluginconfig.h"
#include "blackgui/plugindetailswindow.h"
#include "blackmisc/simulation/simulatorplugininfolist.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
@@ -24,8 +25,10 @@ namespace BlackGui
CSettingsSimulatorComponent::CSettingsSimulatorComponent(QWidget *parent) :
QFrame(parent),
CEnableForRuntime(nullptr, false),
ui(new Ui::CSettingsSimulatorComponent)
ui(new Ui::CSettingsSimulatorComponent),
m_plugins(new CPluginManagerSimulator(this))
{
m_plugins->collectPlugins();
ui->setupUi(this);
CLedWidget::LedShape shape = CLedWidget::Circle;
this->ui->led_RestrictedRendering->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "Limited", "Unlimited", 14);
@@ -42,13 +45,15 @@ namespace BlackGui
// set values
for (const auto &p : getAvailablePlugins())
{
ui->ps_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), false);
QString config = m_plugins->getPluginConfigId(p.getIdentifier());
ui->ps_EnabledSimulators->addPlugin(p.getIdentifier(), p.getName(), !config.isEmpty(), false);
}
// connects
connect(this->getIContextSimulator(), &IContextSimulator::simulatorPluginChanged, this, &CSettingsSimulatorComponent::ps_simulatorPluginChanged);
connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginStateChanged, this, &CSettingsSimulatorComponent::ps_pluginStateChanged);
connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginDetailsRequested, this, &CSettingsSimulatorComponent::ps_showPluginDetails);
connect(this->ui->ps_EnabledSimulators, &CPluginSelector::pluginConfigRequested, this, &CSettingsSimulatorComponent::ps_showPluginConfig);
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);
@@ -262,6 +267,24 @@ namespace BlackGui
w->show();
}
void CSettingsSimulatorComponent::ps_showPluginConfig(const QString &identifier)
{
CSimulatorPluginInfoList simDrivers(getAvailablePlugins());
auto selected = std::find_if(simDrivers.begin(), simDrivers.end(),
[&identifier](const CSimulatorPluginInfo &info)
{
return info.getIdentifier() == identifier;
});
QString configId = m_plugins->getPluginConfigId(selected->getIdentifier());
IPluginConfig *config = m_plugins->getPluginById<IPluginConfig>(configId);
QWidget *window = config->createConfigWindow();
// window->setParent(qApp->activeWindow());
window->setWindowFlags(Qt::Dialog);
window->setAttribute(Qt::WA_DeleteOnClose);
window->show();
}
}
} // namespace

View File

@@ -10,6 +10,7 @@
#ifndef BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#define BLACKGUI_SETTINGSSIMULATORCOMPONENT_H
#include "blackcore/plugin_manager_simulator.h"
#include "blackgui/blackguiexport.h"
#include "blackmisc/simulation/simulatorplugininfolist.h"
#include "enableforruntime.h"
@@ -64,6 +65,9 @@ namespace BlackGui
//! Open plugin details window
void ps_showPluginDetails(const QString &identifier);
//! Show plugin config
void ps_showPluginConfig(const QString &identifier);
private:
//! Set the GUI values
@@ -74,6 +78,8 @@ namespace BlackGui
QScopedPointer<Ui::CSettingsSimulatorComponent> ui; //!< UI
bool m_pluginLoaded = false; //!< plugin loaded
BlackCore::CPluginManagerSimulator* m_plugins = nullptr;
};
}
} // namespace

View File

@@ -0,0 +1,36 @@
/* Copyright (C) 2015
* 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.
*
* Class based on qLed: Copyright (C) 2010 by P. Sereno, http://www.sereno-online.com
*/
//! \file
#ifndef BLACKGUI_PLUGINCONFIG_H
#define BCLAKGUI_PLUGINCONFIG_H
#include "blackgui/blackguiexport.h"
#include <QtWidgets/QWidget>
#include <QtPlugin>
namespace BlackGui
{
class BLACKGUI_EXPORT IPluginConfig
{
public:
virtual ~IPluginConfig() = default;
virtual QWidget *createConfigWindow() = 0;
};
}
Q_DECLARE_INTERFACE(BlackGui::IPluginConfig, "org.swift-project.blackgui.pluginconfiginterface")
#endif // guard

View File

@@ -19,17 +19,19 @@ namespace BlackGui
{
CPluginSelector::CPluginSelector(QWidget *parent) : QWidget(parent),
m_mapper(new QSignalMapper(this))
m_detailsButtonMapper(new QSignalMapper(this)),
m_configButtonMapper(new QSignalMapper(this))
{
setObjectName("CPluginSelector");
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
connect(m_mapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), this, &CPluginSelector::pluginDetailsRequested);
connect(m_detailsButtonMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), this, &CPluginSelector::pluginDetailsRequested);
connect(m_configButtonMapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), this, &CPluginSelector::pluginConfigRequested);
}
void CPluginSelector::addPlugin(const QString& identifier, const QString &name, bool enabled)
void CPluginSelector::addPlugin(const QString& identifier, const QString &name, bool hasConfig, bool enabled)
{
QWidget *pw = new QWidget;
QHBoxLayout *layout = new QHBoxLayout;
@@ -51,21 +53,20 @@ namespace BlackGui
pw->layout()->addWidget(cb);
QPushButton *details = new QPushButton("?");
m_mapper->setMapping(details, identifier);
connect(details, &QPushButton::clicked, m_mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
m_detailsButtonMapper->setMapping(details, identifier);
connect(details, &QPushButton::clicked, m_detailsButtonMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
pw->layout()->addWidget(details);
layout->setStretch(0, 1);
layout->setStretch(1, 0);
/* Might be useful for #392 */
#if 0
QPushButton *pb = new QPushButton("...");
pw->layout()->addWidget(pb);
if (hasConfig) {
QPushButton *config = new QPushButton("...");
m_configButtonMapper->setMapping(config, identifier);
connect(config, &QPushButton::clicked, m_configButtonMapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
pw->layout()->addWidget(config);
}
layout->setStretch(0, 1);
layout->setStretch(1, 0);
#endif
layout->setStretch(2, 0);
this->layout()->addWidget(pw);
}

View File

@@ -35,6 +35,9 @@ namespace BlackGui
//! Emitted when user clicks the "Details" button
void pluginDetailsRequested(const QString &identifier);
//! Emitted when user clicks the "Settings" button
void pluginConfigRequested(const QString &identifier);
public:
//! Constructor
explicit CPluginSelector(QWidget *parent = 0);
@@ -43,13 +46,14 @@ namespace BlackGui
//! \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);
void addPlugin(const QString &identifier, const QString &name, bool hasConfig = false, bool enabled = true);
private slots:
void ps_handlePluginStateChange();
private:
QSignalMapper *m_mapper;
QSignalMapper *m_detailsButtonMapper;
QSignalMapper *m_configButtonMapper;
};