1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-99 gcs Import/Export Plugin: Support configurable plugins

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2732 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
erhard 2011-02-05 14:01:18 +00:00 committed by erhard
parent 9a5d099a79
commit eab8421e5f
9 changed files with 62 additions and 21 deletions

View File

@ -12,6 +12,7 @@ namespace Core {
class CORE_EXPORT IConfigurablePlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
public:
// IConfigurablePlugin(QObject *parent = 0){}
virtual ~IConfigurablePlugin() {}

View File

@ -285,7 +285,7 @@ void MainWindow::extensionsInitialized()
// qDebug() << "Number of keys in config: " << qs->allKeys().count();
m_uavGadgetInstanceManager = new UAVGadgetInstanceManager(this);
m_uavGadgetInstanceManager->readConfigurations(qs);
m_uavGadgetInstanceManager->readSettings(qs);
m_messageManager->init();
readSettings(qs);
@ -313,7 +313,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
emit m_coreImpl->coreAboutToClose();
saveSettings(m_settings);
m_uavGadgetInstanceManager->writeConfigurations(m_settings);
m_uavGadgetInstanceManager->saveSettings(m_settings);
event->accept();
}

View File

@ -70,7 +70,7 @@ UAVGadgetInstanceManager::~UAVGadgetInstanceManager()
}
void UAVGadgetInstanceManager::readConfigurations(QSettings *qs)
void UAVGadgetInstanceManager::readSettings(QSettings *qs)
{
while ( !m_configurations.isEmpty() ){
emit configurationToBeDeleted(m_configurations.takeLast());
@ -204,7 +204,7 @@ void UAVGadgetInstanceManager::readConfigs_1_1_0(QSettings *qs)
}
}
void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs)
void UAVGadgetInstanceManager::saveSettings(QSettings *qs)
{
UAVConfigInfo *configInfo;
qs->beginGroup("UAVGadgetConfigurations");

View File

@ -58,8 +58,8 @@ Q_OBJECT
public:
explicit UAVGadgetInstanceManager(QObject *parent = 0);
~UAVGadgetInstanceManager();
void readConfigurations(QSettings *qs);
void writeConfigurations(QSettings *qs);
void readSettings(QSettings *qs);
void saveSettings(QSettings *qs);
IUAVGadget *createGadget(QString classId, QWidget *parent);
void removeGadget(IUAVGadget *gadget);
void removeAllGadgets();

View File

@ -47,8 +47,7 @@ ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId
if ( !configInfo->standardVersionHandlingOK(VERSION))
return;
iniFile = qSettings->value("dialFile", "gcs.ini").toString(); // TODO Delete with next minor version.
iniFile = qSettings->value("iniFile", iniFile).toString();
iniFile = qSettings->value("iniFile", "gcs.xml").toString();
}
/**
@ -68,7 +67,6 @@ IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
*/
void ImportExportGadgetConfiguration::saveConfig(QSettings* qSettings, Core::UAVConfigInfo *configInfo) const {
configInfo->setVersion(VERSION);
qSettings->setValue("dialFile", iniFile);
qSettings->setValue("iniFile", iniFile);
}

View File

@ -52,7 +52,7 @@ QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
// Restore the contents from the settings:
options_page->iniFile->setExpectedKind(Utils::PathChooser::File);
options_page->iniFile->setPromptDialogFilter(tr("INI file (*.ini)"));
options_page->iniFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)"));
options_page->iniFile->setPromptDialogTitle(tr("Choose configuration file"));
options_page->iniFile->setPath(m_config->getIniFile());

View File

@ -31,6 +31,8 @@
#include "xmlconfig.h"
#include "coreplugin/uavgadgetinstancemanager.h"
#include "coreplugin/icore.h"
#include <extensionsystem/pluginmanager.h>
#include <extensionsystem/pluginspec.h>
#include <QtDebug>
#include <QSettings>
#include <QMessageBox>
@ -47,7 +49,7 @@ ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) :
ui->setupUi(this);
ui->configFile->setExpectedKind(Utils::PathChooser::File);
ui->configFile->setPromptDialogFilter(tr("INI file (*.ini);; XML file (*.xml)"));
ui->configFile->setPromptDialogTitle(tr("Choose filename"));
ui->configFile->setPromptDialogTitle(tr("Choose configuration file"));
}
@ -111,11 +113,26 @@ void ImportExportGadgetWidget::on_exportButton_clicked()
}
QList<Core::IConfigurablePlugin*> ImportExportGadgetWidget::getConfigurables()
{
QList<Core::IConfigurablePlugin*> configurables;
QList<ExtensionSystem::PluginSpec *> specs = ExtensionSystem::PluginManager::instance()->plugins();
foreach ( ExtensionSystem::PluginSpec* spec, specs ){
if ( Core::IConfigurablePlugin* plugin = dynamic_cast<Core::IConfigurablePlugin*>(spec->plugin()) ){
qDebug()<< "Configurable: " << plugin->metaObject()->className();
configurables.append(plugin);
}
}
return configurables;
}
void ImportExportGadgetWidget::exportConfiguration(const QString& fileName)
{
bool general = ui->checkBoxGeneral->isChecked();
bool allGadgets = ui->checkBoxAllGadgets->isChecked();
bool doGeneral = ui->checkBoxGeneral->isChecked();
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings::Format format;
if ( ui->radioButtonIniFormat->isChecked() ){
format = QSettings::IniFormat;
@ -130,12 +147,18 @@ void ImportExportGadgetWidget::exportConfiguration(const QString& fileName)
QSettings qs(fileName, format);
if (general) {
if (doGeneral) {
Core::ICore::instance()->saveMainSettings(&qs);
}
if (allGadgets) {
Core::ICore::instance()->uavGadgetInstanceManager()->writeConfigurations(&qs);
if (doAllGadgets) {
Core::ICore::instance()->uavGadgetInstanceManager()->saveSettings(&qs);
}
if ( doPlugins ){
foreach ( Core::IConfigurablePlugin *plugin, getConfigurables()){
Core::ICore::instance()->saveSettings(plugin,&qs);
}
}
qDebug() << "Export ended";
}
@ -166,8 +189,10 @@ void ImportExportGadgetWidget::on_importButton_clicked()
void ImportExportGadgetWidget::importConfiguration(const QString& fileName)
{
bool general = ui->checkBoxGeneral->isChecked();
bool allGadgets = ui->checkBoxAllGadgets->isChecked();
bool doGeneral = ui->checkBoxGeneral->isChecked();
bool doAllGadgets = ui->checkBoxAllGadgets->isChecked();
bool doPlugins = ui->checkBoxPlugins->isChecked();
QSettings::Format format;
if ( ui->radioButtonIniFormat->isChecked() ){
format = QSettings::IniFormat;
@ -182,12 +207,17 @@ void ImportExportGadgetWidget::importConfiguration(const QString& fileName)
QSettings qs(fileName, format);
if (allGadgets) {
Core::ICore::instance()->uavGadgetInstanceManager()->readConfigurations(&qs);
if ( doAllGadgets ) {
Core::ICore::instance()->uavGadgetInstanceManager()->readSettings(&qs);
}
if (general) {
if ( doGeneral ) {
Core::ICore::instance()->readMainSettings(&qs);
}
if ( doPlugins ){
foreach ( Core::IConfigurablePlugin *plugin, getConfigurables()){
Core::ICore::instance()->readSettings(plugin,&qs);
}
}
qDebug() << "Import ended";
}

View File

@ -13,6 +13,7 @@
#include <QWidget>
#include <QString>
#include <coreplugin/iconfigurableplugin.h>
#include "importexportgadgetconfiguration.h"
namespace Ui
@ -40,6 +41,7 @@ private:
void writeError(const QString&) const;
void exportConfiguration(const QString& fileName);
void importConfiguration(const QString& fileName);
QList<Core::IConfigurablePlugin*> getConfigurables();
private slots:
void on_helpButton_clicked();

View File

@ -67,6 +67,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxPlugins">
<property name="text">
<string>Plugins</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>