From eab8421e5f26be0584636459f738683a81bc6e6d Mon Sep 17 00:00:00 2001 From: erhard Date: Sat, 5 Feb 2011 14:01:18 +0000 Subject: [PATCH] OP-99 gcs Import/Export Plugin: Support configurable plugins git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2732 ebee16cc-31ac-478f-84a7-5cbb03baadba --- .../plugins/coreplugin/iconfigurableplugin.h | 1 + .../src/plugins/coreplugin/mainwindow.cpp | 4 +- .../coreplugin/uavgadgetinstancemanager.cpp | 4 +- .../coreplugin/uavgadgetinstancemanager.h | 4 +- .../importexportgadgetconfiguration.cpp | 4 +- .../importexportgadgetoptionspage.cpp | 2 +- .../importexport/importexportgadgetwidget.cpp | 52 +++++++++++++++---- .../importexport/importexportgadgetwidget.h | 2 + .../importexport/importexportgadgetwidget.ui | 10 ++++ 9 files changed, 62 insertions(+), 21 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/iconfigurableplugin.h b/ground/openpilotgcs/src/plugins/coreplugin/iconfigurableplugin.h index a0f66f46d..951530062 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/iconfigurableplugin.h +++ b/ground/openpilotgcs/src/plugins/coreplugin/iconfigurableplugin.h @@ -12,6 +12,7 @@ namespace Core { class CORE_EXPORT IConfigurablePlugin : public ExtensionSystem::IPlugin { + Q_OBJECT public: // IConfigurablePlugin(QObject *parent = 0){} virtual ~IConfigurablePlugin() {} diff --git a/ground/openpilotgcs/src/plugins/coreplugin/mainwindow.cpp b/ground/openpilotgcs/src/plugins/coreplugin/mainwindow.cpp index 6db5d9c25..16a57fd0a 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/mainwindow.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/mainwindow.cpp @@ -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(); } diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 4776a7050..f93e5cb60 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -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"); diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h index 3fc3b31c4..1b8f574ee 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h @@ -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(); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp index c26354bc0..8e97c9bec 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetconfiguration.cpp @@ -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); } diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp index f06326ea3..ade45bb5f 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetoptionspage.cpp @@ -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()); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp index e886176ba..21f5d7675 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.cpp @@ -31,6 +31,8 @@ #include "xmlconfig.h" #include "coreplugin/uavgadgetinstancemanager.h" #include "coreplugin/icore.h" +#include +#include #include #include #include @@ -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 ImportExportGadgetWidget::getConfigurables() +{ + QList configurables; + + QList specs = ExtensionSystem::PluginManager::instance()->plugins(); + foreach ( ExtensionSystem::PluginSpec* spec, specs ){ + if ( Core::IConfigurablePlugin* plugin = dynamic_cast(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"; } diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h index 776953f7c..32b48c81e 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.h @@ -13,6 +13,7 @@ #include #include +#include #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 getConfigurables(); private slots: void on_helpButton_clicked(); diff --git a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui index ce65c98d3..f20c666e4 100644 --- a/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui +++ b/ground/openpilotgcs/src/plugins/importexport/importexportgadgetwidget.ui @@ -67,6 +67,16 @@ + + + + Plugins + + + true + + +