mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
Initial revision of Import/Export Plugin
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1211 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
89dba4002d
commit
ded496310e
@ -1,353 +1,385 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetinstancemanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavgadgetinstancemanager.h"
|
||||
#include "iuavgadget.h"
|
||||
#include "uavgadgetdecorator.h"
|
||||
#include "iuavgadgetfactory.h"
|
||||
#include "iuavgadgetconfiguration.h"
|
||||
#include "uavgadgetoptionspagedecorator.h"
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include "coreplugin/dialogs/settingsdialog.h"
|
||||
#include "icore.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
|
||||
using namespace Core;
|
||||
|
||||
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_pm = ExtensionSystem::PluginManager::instance();
|
||||
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
|
||||
foreach (IUAVGadgetFactory *f, factories) {
|
||||
if (!m_factories.contains(f)) {
|
||||
m_factories.append(f);
|
||||
QString classId = f->classId();
|
||||
QString name = f->name();
|
||||
m_classIds.insert(classId, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UAVGadgetInstanceManager::~UAVGadgetInstanceManager()
|
||||
{
|
||||
foreach (IOptionsPage *page, m_optionsPages) {
|
||||
m_pm->removeObject(page);
|
||||
delete page;
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::readConfigurations()
|
||||
{
|
||||
QSettings *qs = Core::ICore::instance()->settings();
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
foreach (QString classId, m_classIds.keys())
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
qs->beginGroup(classId);
|
||||
QStringList configs = qs->childKeys();
|
||||
|
||||
foreach (QString configName, configs) {
|
||||
QByteArray ba = QByteArray::fromBase64(qs->value(configName).toByteArray());
|
||||
QDataStream stream(ba);
|
||||
bool locked;
|
||||
stream >> locked;
|
||||
QByteArray state;
|
||||
stream >> state;
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(state);
|
||||
config->setName(configName);
|
||||
config->setProvisionalName(configName);
|
||||
config->setLocked(locked);
|
||||
if (config)
|
||||
m_configurations.append(config);
|
||||
}
|
||||
|
||||
if (configs.count() == 0) {
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(0);
|
||||
// it is not mandatory for uavgadgets to have any configurations (settings)
|
||||
// and therefore we have to check for that
|
||||
if (config) {
|
||||
config->setName(tr("default"));
|
||||
config->setProvisionalName(tr("default"));
|
||||
m_configurations.append(config);
|
||||
}
|
||||
}
|
||||
qs->endGroup();
|
||||
}
|
||||
qs->endGroup();
|
||||
createOptionsPages();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::writeConfigurations()
|
||||
{
|
||||
QSettings *qs = Core::ICore::instance()->settings();
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
qs->remove(""); // Remove existing configurations
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
qs->beginGroup(config->classId());
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||
stream << config->locked();
|
||||
stream << config->saveState();
|
||||
qs->setValue(config->name(), ba.toBase64());
|
||||
qs->endGroup();
|
||||
}
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::createOptionsPages()
|
||||
{
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
if (p) {
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
m_optionsPages.append(page);
|
||||
m_pm->addObject(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent)
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
if (f) {
|
||||
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
||||
IUAVGadget *g = f->createGadget(parent);
|
||||
IUAVGadget *gadget = new UAVGadgetDecorator(g, configs);
|
||||
m_gadgetInstances.append(gadget);
|
||||
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
|
||||
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
|
||||
connect(this, SIGNAL(configurationNameChanged(IUAVGadgetConfiguration*, QString,QString)), gadget, SLOT(configurationNameChanged(IUAVGadgetConfiguration*, QString,QString)));
|
||||
connect(this, SIGNAL(configurationToBeDeleted(IUAVGadgetConfiguration*)), gadget, SLOT(configurationToBeDeleted(IUAVGadgetConfiguration*)));
|
||||
return gadget;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::removeGadget(IUAVGadget *gadget)
|
||||
{
|
||||
if (m_gadgetInstances.contains(gadget)) {
|
||||
m_gadgetInstances.removeOne(gadget);
|
||||
delete gadget;
|
||||
gadget = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool UAVGadgetInstanceManager::canDeleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
// to be able to delete a configuration, no instance must be using it
|
||||
foreach (IUAVGadget *gadget, m_gadgetInstances) {
|
||||
if (gadget->activeConfiguration() == config) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// and it cannot be the only configuration
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
if (c != config && c->classId() == config->classId())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
m_provisionalDeletes.append(config);
|
||||
if (m_provisionalConfigs.contains(config)) {
|
||||
int i = m_provisionalConfigs.indexOf(config);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_provisionalOptionsPages.removeAt(i);
|
||||
int j = m_takenNames[config->classId()].indexOf(config->name());
|
||||
m_takenNames[config->classId()].removeAt(j);
|
||||
m_settingsDialog->deletePage();
|
||||
} else if (m_configurations.contains(config)) {
|
||||
m_settingsDialog->deletePage();
|
||||
}
|
||||
configurationNameEdited("", false);
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *configToClone)
|
||||
{
|
||||
QString name = suggestName(configToClone->classId(), configToClone->name());
|
||||
|
||||
IUAVGadgetConfiguration *config = configToClone->clone();
|
||||
config->setName(name);
|
||||
config->setProvisionalName(name);
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
m_provisionalConfigs.append(config);
|
||||
m_provisionalOptionsPages.append(page);
|
||||
m_settingsDialog->insertPage(page);
|
||||
}
|
||||
|
||||
// "name" => "name 1", "Name 3" => "Name 4", "Name1" => "Name1 1"
|
||||
QString UAVGadgetInstanceManager::suggestName(QString classId, QString name)
|
||||
{
|
||||
QString suggestedName;
|
||||
|
||||
QString last = name.split(" ").last();
|
||||
bool ok;
|
||||
int num = last.toInt(&ok);
|
||||
int i = 1;
|
||||
if (ok) {
|
||||
QStringList n = name.split(" ");
|
||||
n.removeLast();
|
||||
name = n.join(" ");
|
||||
i = num+1;
|
||||
}
|
||||
do {
|
||||
suggestedName = name + " " + QString::number(i);
|
||||
++i;
|
||||
} while (m_takenNames[classId].contains(suggestedName));
|
||||
|
||||
m_takenNames[classId].append(suggestedName);
|
||||
return suggestedName;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (m_provisionalDeletes.contains(config)) {
|
||||
m_provisionalDeletes.removeAt(m_provisionalDeletes.indexOf(config));
|
||||
int i = m_configurations.indexOf(config);
|
||||
if (i >= 0) {
|
||||
emit configurationToBeDeleted(config);
|
||||
int j = m_takenNames[config->classId()].indexOf(config->name());
|
||||
m_takenNames[config->classId()].removeAt(j);
|
||||
m_pm->removeObject(m_optionsPages.at(i));
|
||||
m_configurations.removeAt(i);
|
||||
m_optionsPages.removeAt(i);//TODO delete
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (config->provisionalName() != config->name()) {
|
||||
emit configurationNameChanged(config, config->name(), config->provisionalName());
|
||||
config->setName(config->provisionalName());
|
||||
}
|
||||
if (m_configurations.contains(config)) {
|
||||
emit configurationChanged(config);
|
||||
} else if (m_provisionalConfigs.contains(config)) {
|
||||
emit configurationAdded(config);
|
||||
int i = m_provisionalConfigs.indexOf(config);
|
||||
IOptionsPage *page = m_provisionalOptionsPages.at(i);
|
||||
m_configurations.append(config);
|
||||
m_optionsPages.append(page);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_provisionalOptionsPages.removeAt(i);
|
||||
m_pm->addObject(page);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::configurationNameEdited(QString text, bool hasText)
|
||||
{
|
||||
bool disable = false;
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_configurations) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *c, m_provisionalConfigs) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
if (hasText && text == "")
|
||||
disable = true;
|
||||
m_settingsDialog->disableApplyOk(disable);
|
||||
if (hasText)
|
||||
m_settingsDialog->updateText(text);
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog)
|
||||
{
|
||||
foreach (QString classId, classIds())
|
||||
m_takenNames.insert(classId, configurationNames(classId));
|
||||
m_settingsDialog = settingsDialog;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogRemoved()
|
||||
{
|
||||
m_takenNames.clear();
|
||||
m_provisionalConfigs.clear();
|
||||
m_provisionalDeletes.clear();
|
||||
m_provisionalOptionsPages.clear(); //TODO delete
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
config->setProvisionalName(config->name());
|
||||
m_settingsDialog = 0;
|
||||
}
|
||||
|
||||
QStringList UAVGadgetInstanceManager::configurationNames(QString classId) const
|
||||
{
|
||||
QStringList names;
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
names.append(config->name());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
QString UAVGadgetInstanceManager::gadgetName(QString classId) const
|
||||
{
|
||||
return m_classIds.value(classId);
|
||||
}
|
||||
|
||||
IUAVGadgetFactory *UAVGadgetInstanceManager::factory(QString classId) const
|
||||
{
|
||||
foreach (IUAVGadgetFactory *f, m_factories) {
|
||||
if (f->classId() == classId)
|
||||
return f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<IUAVGadgetConfiguration*> *UAVGadgetInstanceManager::configurations(QString classId) const
|
||||
{
|
||||
QList<IUAVGadgetConfiguration*> *configs = new QList<IUAVGadgetConfiguration*>;
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
configs->append(config);
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetinstancemanager.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "uavgadgetinstancemanager.h"
|
||||
#include "iuavgadget.h"
|
||||
#include "uavgadgetdecorator.h"
|
||||
#include "iuavgadgetfactory.h"
|
||||
#include "iuavgadgetconfiguration.h"
|
||||
#include "uavgadgetoptionspagedecorator.h"
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include "coreplugin/dialogs/settingsdialog.h"
|
||||
#include "icore.h"
|
||||
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QMessageBox>
|
||||
|
||||
|
||||
using namespace Core;
|
||||
|
||||
UAVGadgetInstanceManager::UAVGadgetInstanceManager(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_pm = ExtensionSystem::PluginManager::instance();
|
||||
QList<IUAVGadgetFactory*> factories = m_pm->getObjects<IUAVGadgetFactory>();
|
||||
foreach (IUAVGadgetFactory *f, factories) {
|
||||
if (!m_factories.contains(f)) {
|
||||
m_factories.append(f);
|
||||
QString classId = f->classId();
|
||||
QString name = f->name();
|
||||
m_classIds.insert(classId, name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UAVGadgetInstanceManager::~UAVGadgetInstanceManager()
|
||||
{
|
||||
foreach (IOptionsPage *page, m_optionsPages) {
|
||||
m_pm->removeObject(page);
|
||||
delete page;
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::readConfigurations()
|
||||
{
|
||||
readConfigurations(Core::ICore::instance()->settings());
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::readConfigurations(QSettings *qs)
|
||||
{
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
foreach (QString classId, m_classIds.keys())
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
qs->beginGroup(classId);
|
||||
QStringList configs = qs->childKeys();
|
||||
|
||||
foreach (QString configName, configs) {
|
||||
QByteArray ba = QByteArray::fromBase64(qs->value(configName).toByteArray());
|
||||
QDataStream stream(ba);
|
||||
bool locked;
|
||||
stream >> locked;
|
||||
QByteArray state;
|
||||
stream >> state;
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(state);
|
||||
if (config){
|
||||
config->setName(configName);
|
||||
config->setProvisionalName(configName);
|
||||
config->setLocked(locked);
|
||||
int idx = indexForConfig(m_configurations, classId, configName);
|
||||
if ( idx >= 0 ){
|
||||
// We should replace the config, but it might be used, so just
|
||||
// throw it out of the list. The GCS should be reinitialised soon.
|
||||
m_configurations[idx] = config;
|
||||
}
|
||||
else{
|
||||
m_configurations.append(config);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (configs.count() == 0) {
|
||||
IUAVGadgetConfiguration *config = f->createConfiguration(0);
|
||||
// it is not mandatory for uavgadgets to have any configurations (settings)
|
||||
// and therefore we have to check for that
|
||||
if (config) {
|
||||
config->setName(tr("default"));
|
||||
config->setProvisionalName(tr("default"));
|
||||
m_configurations.append(config);
|
||||
}
|
||||
}
|
||||
qs->endGroup();
|
||||
}
|
||||
qs->endGroup();
|
||||
createOptionsPages();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::writeConfigurations()
|
||||
{
|
||||
writeConfigurations(Core::ICore::instance()->settings());
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::writeConfigurations(QSettings *qs)
|
||||
{
|
||||
qs->beginGroup("UAVGadgetConfigurations");
|
||||
qs->remove(""); // Remove existing configurations
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
qs->beginGroup(config->classId());
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::WriteOnly);
|
||||
stream << config->locked();
|
||||
stream << config->saveState();
|
||||
qs->setValue(config->name(), ba.toBase64());
|
||||
qs->endGroup();
|
||||
}
|
||||
qs->endGroup();
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::createOptionsPages()
|
||||
{
|
||||
// In case there are pages (import a configuration), remove them.
|
||||
// Maybe they should be deleted as well (memory-leak),
|
||||
// but this might lead to NULL-pointers?
|
||||
while (!m_optionsPages.isEmpty()){
|
||||
m_pm->removeObject(m_optionsPages.takeLast());
|
||||
}
|
||||
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
if (p) {
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
m_optionsPages.append(page);
|
||||
m_pm->addObject(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent)
|
||||
{
|
||||
IUAVGadgetFactory *f = factory(classId);
|
||||
if (f) {
|
||||
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
|
||||
IUAVGadget *g = f->createGadget(parent);
|
||||
IUAVGadget *gadget = new UAVGadgetDecorator(g, configs);
|
||||
m_gadgetInstances.append(gadget);
|
||||
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
|
||||
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
|
||||
connect(this, SIGNAL(configurationNameChanged(IUAVGadgetConfiguration*, QString,QString)), gadget, SLOT(configurationNameChanged(IUAVGadgetConfiguration*, QString,QString)));
|
||||
connect(this, SIGNAL(configurationToBeDeleted(IUAVGadgetConfiguration*)), gadget, SLOT(configurationToBeDeleted(IUAVGadgetConfiguration*)));
|
||||
return gadget;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::removeGadget(IUAVGadget *gadget)
|
||||
{
|
||||
if (m_gadgetInstances.contains(gadget)) {
|
||||
m_gadgetInstances.removeOne(gadget);
|
||||
delete gadget;
|
||||
gadget = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool UAVGadgetInstanceManager::canDeleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
// to be able to delete a configuration, no instance must be using it
|
||||
foreach (IUAVGadget *gadget, m_gadgetInstances) {
|
||||
if (gadget->activeConfiguration() == config) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// and it cannot be the only configuration
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
if (c != config && c->classId() == config->classId())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::deleteConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
m_provisionalDeletes.append(config);
|
||||
if (m_provisionalConfigs.contains(config)) {
|
||||
int i = m_provisionalConfigs.indexOf(config);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_provisionalOptionsPages.removeAt(i);
|
||||
int j = m_takenNames[config->classId()].indexOf(config->name());
|
||||
m_takenNames[config->classId()].removeAt(j);
|
||||
m_settingsDialog->deletePage();
|
||||
} else if (m_configurations.contains(config)) {
|
||||
m_settingsDialog->deletePage();
|
||||
}
|
||||
configurationNameEdited("", false);
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *configToClone)
|
||||
{
|
||||
QString name = suggestName(configToClone->classId(), configToClone->name());
|
||||
|
||||
IUAVGadgetConfiguration *config = configToClone->clone();
|
||||
config->setName(name);
|
||||
config->setProvisionalName(name);
|
||||
IUAVGadgetFactory *f = factory(config->classId());
|
||||
IOptionsPage *p = f->createOptionsPage(config);
|
||||
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
|
||||
m_provisionalConfigs.append(config);
|
||||
m_provisionalOptionsPages.append(page);
|
||||
m_settingsDialog->insertPage(page);
|
||||
}
|
||||
|
||||
// "name" => "name 1", "Name 3" => "Name 4", "Name1" => "Name1 1"
|
||||
QString UAVGadgetInstanceManager::suggestName(QString classId, QString name)
|
||||
{
|
||||
QString suggestedName;
|
||||
|
||||
QString last = name.split(" ").last();
|
||||
bool ok;
|
||||
int num = last.toInt(&ok);
|
||||
int i = 1;
|
||||
if (ok) {
|
||||
QStringList n = name.split(" ");
|
||||
n.removeLast();
|
||||
name = n.join(" ");
|
||||
i = num+1;
|
||||
}
|
||||
do {
|
||||
suggestedName = name + " " + QString::number(i);
|
||||
++i;
|
||||
} while (m_takenNames[classId].contains(suggestedName));
|
||||
|
||||
m_takenNames[classId].append(suggestedName);
|
||||
return suggestedName;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
if (m_provisionalDeletes.contains(config)) {
|
||||
m_provisionalDeletes.removeAt(m_provisionalDeletes.indexOf(config));
|
||||
int i = m_configurations.indexOf(config);
|
||||
if (i >= 0) {
|
||||
emit configurationToBeDeleted(config);
|
||||
int j = m_takenNames[config->classId()].indexOf(config->name());
|
||||
m_takenNames[config->classId()].removeAt(j);
|
||||
m_pm->removeObject(m_optionsPages.at(i));
|
||||
m_configurations.removeAt(i);
|
||||
m_optionsPages.removeAt(i);//TODO delete
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (config->provisionalName() != config->name()) {
|
||||
emit configurationNameChanged(config, config->name(), config->provisionalName());
|
||||
config->setName(config->provisionalName());
|
||||
}
|
||||
if (m_configurations.contains(config)) {
|
||||
emit configurationChanged(config);
|
||||
} else if (m_provisionalConfigs.contains(config)) {
|
||||
emit configurationAdded(config);
|
||||
int i = m_provisionalConfigs.indexOf(config);
|
||||
IOptionsPage *page = m_provisionalOptionsPages.at(i);
|
||||
m_configurations.append(config);
|
||||
m_optionsPages.append(page);
|
||||
m_provisionalConfigs.removeAt(i);
|
||||
m_provisionalOptionsPages.removeAt(i);
|
||||
m_pm->addObject(page);
|
||||
}
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::configurationNameEdited(QString text, bool hasText)
|
||||
{
|
||||
bool disable = false;
|
||||
foreach (IUAVGadgetConfiguration *c, m_configurations) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_configurations) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
foreach (IUAVGadgetConfiguration *c, m_provisionalConfigs) {
|
||||
foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) {
|
||||
if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName())
|
||||
disable = true;
|
||||
}
|
||||
}
|
||||
if (hasText && text == "")
|
||||
disable = true;
|
||||
m_settingsDialog->disableApplyOk(disable);
|
||||
if (hasText)
|
||||
m_settingsDialog->updateText(text);
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog)
|
||||
{
|
||||
foreach (QString classId, classIds())
|
||||
m_takenNames.insert(classId, configurationNames(classId));
|
||||
m_settingsDialog = settingsDialog;
|
||||
}
|
||||
|
||||
void UAVGadgetInstanceManager::settingsDialogRemoved()
|
||||
{
|
||||
m_takenNames.clear();
|
||||
m_provisionalConfigs.clear();
|
||||
m_provisionalDeletes.clear();
|
||||
m_provisionalOptionsPages.clear(); //TODO delete
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations)
|
||||
config->setProvisionalName(config->name());
|
||||
m_settingsDialog = 0;
|
||||
}
|
||||
|
||||
QStringList UAVGadgetInstanceManager::configurationNames(QString classId) const
|
||||
{
|
||||
QStringList names;
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
names.append(config->name());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
QString UAVGadgetInstanceManager::gadgetName(QString classId) const
|
||||
{
|
||||
return m_classIds.value(classId);
|
||||
}
|
||||
|
||||
IUAVGadgetFactory *UAVGadgetInstanceManager::factory(QString classId) const
|
||||
{
|
||||
foreach (IUAVGadgetFactory *f, m_factories) {
|
||||
if (f->classId() == classId)
|
||||
return f;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QList<IUAVGadgetConfiguration*> *UAVGadgetInstanceManager::configurations(QString classId) const
|
||||
{
|
||||
QList<IUAVGadgetConfiguration*> *configs = new QList<IUAVGadgetConfiguration*>;
|
||||
foreach (IUAVGadgetConfiguration *config, m_configurations) {
|
||||
if (config->classId() == classId)
|
||||
configs->append(config);
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
int UAVGadgetInstanceManager::indexForConfig(QList<IUAVGadgetConfiguration*> configurations,
|
||||
QString classId, QString configName)
|
||||
{
|
||||
for ( int i=0; i<configurations.length(); ++i){
|
||||
if ( configurations.at(i)->classId() == classId
|
||||
&& configurations.at(i)->name() == configName )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -1,101 +1,108 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetinstancemanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVGADGETINSTANCEMANAGER_H
|
||||
#define UAVGADGETINSTANCEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
namespace ExtensionSystem {
|
||||
class PluginManager;
|
||||
}
|
||||
|
||||
namespace Core
|
||||
{
|
||||
|
||||
namespace Internal {
|
||||
class SettingsDialog;
|
||||
}
|
||||
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetConfiguration;
|
||||
class IOptionsPage;
|
||||
class IUAVGadgetFactory;
|
||||
|
||||
class UAVGadgetInstanceManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVGadgetInstanceManager(QObject *parent = 0);
|
||||
~UAVGadgetInstanceManager();
|
||||
void readConfigurations();
|
||||
void writeConfigurations();
|
||||
IUAVGadget *createGadget(QString classId, QWidget *parent);
|
||||
void removeGadget(IUAVGadget *gadget);
|
||||
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void deleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void cloneConfiguration(IUAVGadgetConfiguration *config);
|
||||
void applyChanges(IUAVGadgetConfiguration *config);
|
||||
void configurationNameEdited(QString text, bool hasText = true);
|
||||
QStringList classIds() const { return m_classIds.keys(); }
|
||||
QStringList configurationNames(QString classId) const;
|
||||
QString gadgetName(QString classId) const;
|
||||
|
||||
signals:
|
||||
void configurationChanged(IUAVGadgetConfiguration* config);
|
||||
void configurationAdded(IUAVGadgetConfiguration* config);
|
||||
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
|
||||
void configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName);
|
||||
|
||||
public slots:
|
||||
void settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog);
|
||||
void settingsDialogRemoved();
|
||||
|
||||
private:
|
||||
IUAVGadgetFactory *factory(QString classId) const;
|
||||
void createOptionsPages();
|
||||
QList<IUAVGadgetConfiguration*> *configurations(QString classId) const;
|
||||
QString suggestName(QString classId, QString name);
|
||||
QList<IUAVGadget*> m_gadgetInstances;
|
||||
QList<IUAVGadgetFactory*> m_factories;
|
||||
QList<IUAVGadgetConfiguration*> m_configurations;
|
||||
QList<IOptionsPage*> m_optionsPages;
|
||||
QMap<QString, QString> m_classIds;
|
||||
QMap<QString, QStringList> m_takenNames;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalConfigs;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalDeletes;
|
||||
QList<IOptionsPage*> m_provisionalOptionsPages;
|
||||
Core::Internal::SettingsDialog *m_settingsDialog;
|
||||
ExtensionSystem::PluginManager *m_pm;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // UAVGADGETINSTANCEMANAGER_H
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file uavgadgetinstancemanager.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @addtogroup GCSPlugins GCS Plugins
|
||||
* @{
|
||||
* @addtogroup CorePlugin Core Plugin
|
||||
* @{
|
||||
* @brief The Core GCS plugin
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef UAVGADGETINSTANCEMANAGER_H
|
||||
#define UAVGADGETINSTANCEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QStringList>
|
||||
#include "core_global.h"
|
||||
|
||||
namespace ExtensionSystem {
|
||||
class PluginManager;
|
||||
}
|
||||
|
||||
namespace Core
|
||||
{
|
||||
|
||||
namespace Internal {
|
||||
class SettingsDialog;
|
||||
}
|
||||
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetConfiguration;
|
||||
class IOptionsPage;
|
||||
class IUAVGadgetFactory;
|
||||
|
||||
class CORE_EXPORT UAVGadgetInstanceManager : public QObject
|
||||
{
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UAVGadgetInstanceManager(QObject *parent = 0);
|
||||
~UAVGadgetInstanceManager();
|
||||
void readConfigurations();
|
||||
void readConfigurations(QSettings *qs);
|
||||
void writeConfigurations();
|
||||
void writeConfigurations(QSettings *qs);
|
||||
IUAVGadget *createGadget(QString classId, QWidget *parent);
|
||||
void removeGadget(IUAVGadget *gadget);
|
||||
bool canDeleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void deleteConfiguration(IUAVGadgetConfiguration *config);
|
||||
void cloneConfiguration(IUAVGadgetConfiguration *config);
|
||||
void applyChanges(IUAVGadgetConfiguration *config);
|
||||
void configurationNameEdited(QString text, bool hasText = true);
|
||||
QStringList classIds() const { return m_classIds.keys(); }
|
||||
QStringList configurationNames(QString classId) const;
|
||||
QString gadgetName(QString classId) const;
|
||||
|
||||
signals:
|
||||
void configurationChanged(IUAVGadgetConfiguration* config);
|
||||
void configurationAdded(IUAVGadgetConfiguration* config);
|
||||
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
|
||||
void configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName);
|
||||
|
||||
public slots:
|
||||
void settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog);
|
||||
void settingsDialogRemoved();
|
||||
|
||||
private:
|
||||
IUAVGadgetFactory *factory(QString classId) const;
|
||||
void createOptionsPages();
|
||||
QList<IUAVGadgetConfiguration*> *configurations(QString classId) const;
|
||||
QString suggestName(QString classId, QString name);
|
||||
QList<IUAVGadget*> m_gadgetInstances;
|
||||
QList<IUAVGadgetFactory*> m_factories;
|
||||
QList<IUAVGadgetConfiguration*> m_configurations;
|
||||
QList<IOptionsPage*> m_optionsPages;
|
||||
QMap<QString, QString> m_classIds;
|
||||
QMap<QString, QStringList> m_takenNames;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalConfigs;
|
||||
QList<IUAVGadgetConfiguration*> m_provisionalDeletes;
|
||||
QList<IOptionsPage*> m_provisionalOptionsPages;
|
||||
Core::Internal::SettingsDialog *m_settingsDialog;
|
||||
ExtensionSystem::PluginManager *m_pm;
|
||||
int indexForConfig(QList<IUAVGadgetConfiguration*> configurations,
|
||||
QString classId, QString configName);
|
||||
|
||||
};
|
||||
|
||||
} // namespace Core
|
||||
|
||||
#endif // UAVGADGETINSTANCEMANAGER_H
|
||||
|
@ -0,0 +1,10 @@
|
||||
<plugin name="ImportExportGadget" version="1.0.0" compatVersion="1.0.0">
|
||||
<vendor>The OpenPilot Project</vendor>
|
||||
<copyright>(C) 2010 Erhard Siegl</copyright>
|
||||
<license>The GNU Public License (GPL) Version 3</license>
|
||||
<description>An bargraph gadget with red/yellow/green zones</description>
|
||||
<url>http://www.openpilot.org</url>
|
||||
<dependencyList>
|
||||
<dependency name="Core" version="1.0.0"/>
|
||||
</dependencyList>
|
||||
</plugin>
|
22
ground/src/plugins/importexport/importexport.pro
Normal file
22
ground/src/plugins/importexport/importexport.pro
Normal file
@ -0,0 +1,22 @@
|
||||
TEMPLATE = lib
|
||||
TARGET = ImportExportGadget
|
||||
DEFINES += IMPORTEXPORT_LIBRARY
|
||||
QT += svg
|
||||
include(../../openpilotgcsplugin.pri)
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
||||
include(importexport_dependencies.pri)
|
||||
HEADERS += importexportplugin.h \
|
||||
importexportgadgetwidget.h
|
||||
HEADERS += importexportgadget.h
|
||||
HEADERS += importexportgadgetfactory.h
|
||||
HEADERS += importexportgadgetconfiguration.h
|
||||
HEADERS += importexportgadgetoptionspage.h
|
||||
SOURCES += importexportplugin.cpp \
|
||||
importexportgadgetwidget.cpp
|
||||
SOURCES += importexportgadget.cpp
|
||||
SOURCES += importexportgadgetfactory.cpp
|
||||
SOURCES += importexportgadgetconfiguration.cpp
|
||||
SOURCES += importexportgadgetoptionspage.cpp
|
||||
OTHER_FILES += ImportExportGadget.pluginspec
|
||||
FORMS += importexportgadgetoptionspage.ui \
|
||||
importexportgadgetwidget.ui
|
@ -0,0 +1 @@
|
||||
include(../../plugins/coreplugin/coreplugin.pri)
|
39
ground/src/plugins/importexport/importexport_global.h
Normal file
39
ground/src/plugins/importexport/importexport_global.h
Normal file
@ -0,0 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexport_global.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORT_GLOBAL_H
|
||||
#define IMPORTEXPORT_GLOBAL_H
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(IMPORTEXPORT_LIBRARY)
|
||||
# define IMPORTEXPORT_EXPORT Q_DECL_EXPORT
|
||||
#else
|
||||
# define IMPORTEXPORT_EXPORT Q_DECL_IMPORT
|
||||
#endif
|
||||
|
||||
#endif // IMPORTEXPORT_GLOBAL_H
|
52
ground/src/plugins/importexport/importexportgadget.cpp
Normal file
52
ground/src/plugins/importexport/importexportgadget.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadget.cpp
|
||||
* @author Erhard Siegl Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "importexportgadget.h"
|
||||
#include "importexportgadgetwidget.h"
|
||||
#include "importexportgadgetconfiguration.h"
|
||||
|
||||
ImportExportGadget::ImportExportGadget(QString classId, ImportExportGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget)
|
||||
{
|
||||
}
|
||||
|
||||
ImportExportGadget::~ImportExportGadget()
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
This is called when a configuration is loaded, and updates the plugin's settings.
|
||||
Careful: the plugin is already drawn before the loadConfiguration method is called the
|
||||
first time, so you have to be careful not to assume all the plugin values are initialized
|
||||
the first time you use them
|
||||
*/
|
||||
void ImportExportGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
ImportExportGadgetConfiguration *m = qobject_cast<ImportExportGadgetConfiguration*>(config);
|
||||
m_widget->setDialFile(m->getDialFile());
|
||||
}
|
56
ground/src/plugins/importexport/importexportgadget.h
Normal file
56
ground/src/plugins/importexport/importexportgadget.h
Normal file
@ -0,0 +1,56 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadget.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief Bargraph gadget with red/yellow/green zones
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORTGADGET_H_
|
||||
#define IMPORTEXPORTGADGET_H_
|
||||
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
#include "importexportgadgetwidget.h"
|
||||
|
||||
class IUAVGadget;
|
||||
class QWidget;
|
||||
class QString;
|
||||
class ImportExportGadgetWidget;
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class IMPORTEXPORT_EXPORT ImportExportGadget : public Core::IUAVGadget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportExportGadget(QString classId, ImportExportGadgetWidget *widget, QWidget *parent = 0);
|
||||
~ImportExportGadget();
|
||||
|
||||
QWidget *widget() { return m_widget; }
|
||||
void loadConfiguration(IUAVGadgetConfiguration* config);
|
||||
|
||||
private:
|
||||
ImportExportGadgetWidget *m_widget;
|
||||
};
|
||||
|
||||
|
||||
#endif // IMPORTEXPORTGADGET_H_
|
@ -0,0 +1,65 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetconfiguration.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Linear dial Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "importexportgadgetconfiguration.h"
|
||||
#include <QtCore/QDataStream>
|
||||
|
||||
/**
|
||||
* Loads a saved configuration or defaults if non exist.
|
||||
*
|
||||
*/
|
||||
ImportExportGadgetConfiguration::ImportExportGadgetConfiguration(QString classId, const QByteArray &state, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
dialFile("gcs.ini")
|
||||
{
|
||||
//if a saved configuration exists load it
|
||||
if (state.count() > 0) {
|
||||
QDataStream stream(state);
|
||||
stream >> dialFile;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Clones a configuration.
|
||||
*
|
||||
*/
|
||||
IUAVGadgetConfiguration *ImportExportGadgetConfiguration::clone()
|
||||
{
|
||||
ImportExportGadgetConfiguration *m = new ImportExportGadgetConfiguration(this->classId());
|
||||
m->dialFile=dialFile;
|
||||
return m;
|
||||
}
|
||||
/**
|
||||
* Saves a configuration.
|
||||
*
|
||||
*/
|
||||
QByteArray ImportExportGadgetConfiguration::saveState() const
|
||||
{
|
||||
QByteArray bytes;
|
||||
QDataStream stream(&bytes, QIODevice::WriteOnly);
|
||||
stream << dialFile;
|
||||
return bytes;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetconfiguration.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Airspeed Plugin Gadget configuration
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORTGADGETCONFIGURATION_H
|
||||
#define IMPORTEXPORTGADGETCONFIGURATION_H
|
||||
|
||||
#include <coreplugin/iuavgadgetconfiguration.h>
|
||||
#include "importexport_global.h"
|
||||
|
||||
using namespace Core;
|
||||
|
||||
/* This is a generic bargraph dial
|
||||
supporting one indicator.
|
||||
*/
|
||||
class IMPORTEXPORT_EXPORT ImportExportGadgetConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImportExportGadgetConfiguration(QString classId, const QByteArray &state = 0, QObject *parent = 0);
|
||||
|
||||
//set dial configuration functions
|
||||
void setDialFile(QString filename){dialFile=filename;}
|
||||
|
||||
//get dial configuration functions
|
||||
QString getDialFile() {return dialFile;}
|
||||
|
||||
QByteArray saveState() const;
|
||||
IUAVGadgetConfiguration *clone();
|
||||
|
||||
private:
|
||||
QString dialFile;
|
||||
};
|
||||
|
||||
#endif // IMPORTEXPORTGADGETCONFIGURATION_H
|
@ -0,0 +1,60 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetfactory.cpp
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "importexportgadgetfactory.h"
|
||||
#include "importexportgadgetwidget.h"
|
||||
#include "importexportgadget.h"
|
||||
#include "importexportgadgetconfiguration.h"
|
||||
#include "importexportgadgetoptionspage.h"
|
||||
#include <coreplugin/iuavgadget.h>
|
||||
|
||||
ImportExportGadgetFactory::ImportExportGadgetFactory(QObject *parent) :
|
||||
IUAVGadgetFactory(QString("ImportExportGadget"),
|
||||
tr("Import/Export GCS Config"),
|
||||
parent)
|
||||
{
|
||||
}
|
||||
|
||||
ImportExportGadgetFactory::~ImportExportGadgetFactory()
|
||||
{
|
||||
}
|
||||
|
||||
Core::IUAVGadget* ImportExportGadgetFactory::createGadget(QWidget *parent)
|
||||
{
|
||||
ImportExportGadgetWidget* gadgetWidget = new ImportExportGadgetWidget(parent);
|
||||
return new ImportExportGadget(QString("ImportExportGadget"), gadgetWidget, parent);
|
||||
}
|
||||
|
||||
IUAVGadgetConfiguration *ImportExportGadgetFactory::createConfiguration(const QByteArray &state)
|
||||
{
|
||||
return new ImportExportGadgetConfiguration(QString("ImportExportGadget"), state);
|
||||
}
|
||||
|
||||
IOptionsPage *ImportExportGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
return new ImportExportGadgetOptionsPage(qobject_cast<ImportExportGadgetConfiguration*>(config));
|
||||
}
|
||||
|
53
ground/src/plugins/importexport/importexportgadgetfactory.h
Normal file
53
ground/src/plugins/importexport/importexportgadgetfactory.h
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetfactory.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORTGADGETFACTORY_H_
|
||||
#define IMPORTEXPORTGADGETFACTORY_H_
|
||||
|
||||
#include <coreplugin/iuavgadgetfactory.h>
|
||||
#include "importexport_global.h"
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadget;
|
||||
class IUAVGadgetFactory;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class IMPORTEXPORT_EXPORT ImportExportGadgetFactory : public IUAVGadgetFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportExportGadgetFactory(QObject *parent = 0);
|
||||
~ImportExportGadgetFactory();
|
||||
|
||||
Core::IUAVGadget *createGadget(QWidget *parent);
|
||||
IUAVGadgetConfiguration *createConfiguration(const QByteArray &state);
|
||||
IOptionsPage *createOptionsPage(IUAVGadgetConfiguration *config);
|
||||
};
|
||||
|
||||
#endif // IMPORTEXPORTGADGETFACTORY_H_
|
@ -0,0 +1,73 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetoptionspage.cpp
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Linear Dial Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "importexportgadgetoptionspage.h"
|
||||
#include "importexportgadgetconfiguration.h"
|
||||
#include "ui_importexportgadgetoptionspage.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QtDebug>
|
||||
|
||||
ImportExportGadgetOptionsPage::ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
}
|
||||
|
||||
//creates options page widget (uses the UI file)
|
||||
QWidget *ImportExportGadgetOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
|
||||
options_page = new Ui::ImportExportGadgetOptionsPage();
|
||||
//main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
// Restore the contents from the settings:
|
||||
options_page->svgSourceFile->setText(m_config->getDialFile());
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user presses apply or OK.
|
||||
*
|
||||
* Saves the current values
|
||||
*
|
||||
*/
|
||||
void ImportExportGadgetOptionsPage::apply()
|
||||
{
|
||||
m_config->setDialFile(options_page->svgSourceFile->text());
|
||||
}
|
||||
|
||||
|
||||
void ImportExportGadgetOptionsPage::finish()
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportgadgetoptionspage.h
|
||||
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
||||
* @brief Linear Dial Plugin Gadget options page
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORTGADGETOPTIONSPAGE_H
|
||||
#define IMPORTEXPORTGADGETOPTIONSPAGE_H
|
||||
|
||||
#include "importexport_global.h"
|
||||
#include "coreplugin/dialogs/ioptionspage.h"
|
||||
#include <QString>
|
||||
#include <QFont>
|
||||
#include <QStringList>
|
||||
#include <QDebug>
|
||||
|
||||
namespace Core {
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
|
||||
class ImportExportGadgetConfiguration;
|
||||
|
||||
namespace Ui {
|
||||
class ImportExportGadgetOptionsPage;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class IMPORTEXPORT_EXPORT ImportExportGadgetOptionsPage : public IOptionsPage
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ImportExportGadgetOptionsPage(ImportExportGadgetConfiguration *config, QObject *parent = 0);
|
||||
|
||||
QWidget *createPage(QWidget *parent);
|
||||
void apply();
|
||||
void finish();
|
||||
|
||||
private:
|
||||
Ui::ImportExportGadgetOptionsPage *options_page;
|
||||
ImportExportGadgetConfiguration *m_config;
|
||||
QFont font;
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
||||
#endif // IMPORTEXPORTGADGETOPTIONSPAGE_H
|
@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImportExportGadgetOptionsPage</class>
|
||||
<widget class="QWidget" name="ImportExportGadgetOptionsPage">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>486</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="verticalLayoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>-1</x>
|
||||
<y>-1</y>
|
||||
<width>485</width>
|
||||
<height>339</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinimumSize</enum>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMaximumSize</enum>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Default Config File </string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="svgSourceFile"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="loadFile">
|
||||
<property name="text">
|
||||
<string>Load file...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
90
ground/src/plugins/importexport/importexportgadgetwidget.cpp
Normal file
90
ground/src/plugins/importexport/importexportgadgetwidget.cpp
Normal file
@ -0,0 +1,90 @@
|
||||
#include "importexportgadgetwidget.h"
|
||||
#include "ui_importexportgadgetwidget.h"
|
||||
#include "coreplugin/uavgadgetinstancemanager.h"
|
||||
#include "coreplugin/icore.h"
|
||||
#include <QtDebug>
|
||||
#include <QSettings>
|
||||
#include <QMessageBox>
|
||||
|
||||
ImportExportGadgetWidget::ImportExportGadgetWidget(QWidget *parent) :
|
||||
QWidget(parent),
|
||||
ui(new Ui::ImportExportGadgetWidget)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
ImportExportGadgetWidget::~ImportExportGadgetWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ImportExportGadgetWidget::changeEvent(QEvent *e)
|
||||
{
|
||||
QWidget::changeEvent(e);
|
||||
switch (e->type()) {
|
||||
case QEvent::LanguageChange:
|
||||
ui->retranslateUi(this);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ImportExportGadgetWidget::setDialFile(const QString& filename)
|
||||
{
|
||||
ui->configFile->setText(filename);
|
||||
}
|
||||
|
||||
void ImportExportGadgetWidget::on_exportButton_clicked()
|
||||
{
|
||||
QString file = ui->configFile->text();
|
||||
qDebug() << "Export pressed! Write to file " << file;
|
||||
exportConfiguration(file);
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("The settings have been exported to ") + file);
|
||||
msgBox.exec();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ImportExportGadgetWidget::exportConfiguration(const QString& fileName)
|
||||
{
|
||||
QSettings qs(fileName, QSettings::defaultFormat());
|
||||
|
||||
Core::UAVGadgetInstanceManager *im;
|
||||
im = Core::ICore::instance()->uavGadgetInstanceManager();
|
||||
im->writeConfigurations(&qs);
|
||||
|
||||
qDebug() << "Export ended";
|
||||
}
|
||||
|
||||
|
||||
void ImportExportGadgetWidget::writeError(const QString& msg) const
|
||||
{
|
||||
qWarning() << "ERROR: " << msg;
|
||||
}
|
||||
|
||||
void ImportExportGadgetWidget::on_importButton_clicked()
|
||||
{
|
||||
QString file = ui->configFile->text();
|
||||
qDebug() << "Import pressed! Read from file " << file;
|
||||
importConfiguration(file);
|
||||
|
||||
// The new configs are added to the old configs. Things are messy now.
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("The settings have been imported. Restart the application."));
|
||||
msgBox.exec();
|
||||
}
|
||||
|
||||
void ImportExportGadgetWidget::importConfiguration(const QString& fileName)
|
||||
{
|
||||
QSettings qs(fileName, QSettings::defaultFormat());
|
||||
|
||||
Core::UAVGadgetInstanceManager *im;
|
||||
im = Core::ICore::instance()->uavGadgetInstanceManager();
|
||||
im->readConfigurations(&qs);
|
||||
|
||||
qDebug() << "Import ended";
|
||||
}
|
34
ground/src/plugins/importexport/importexportgadgetwidget.h
Normal file
34
ground/src/plugins/importexport/importexportgadgetwidget.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef IMPORTEXPORTGADGETWIDGET_H
|
||||
#define IMPORTEXPORTGADGETWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QString>
|
||||
#include "importexport_global.h"
|
||||
|
||||
namespace Ui {
|
||||
class ImportExportGadgetWidget;
|
||||
}
|
||||
|
||||
class IMPORTEXPORT_EXPORT ImportExportGadgetWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ImportExportGadgetWidget(QWidget *parent = 0);
|
||||
~ImportExportGadgetWidget();
|
||||
|
||||
void setDialFile(const QString& filename);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *e);
|
||||
|
||||
private:
|
||||
Ui::ImportExportGadgetWidget *ui;
|
||||
void writeError(const QString&) const;
|
||||
void exportConfiguration(const QString& fileName);
|
||||
void importConfiguration(const QString& fileName);
|
||||
|
||||
private slots:
|
||||
void on_importButton_clicked();
|
||||
void on_exportButton_clicked();
|
||||
};
|
||||
|
||||
#endif // IMPORTEXPORTGADGETWIDGET_H
|
94
ground/src/plugins/importexport/importexportgadgetwidget.ui
Normal file
94
ground/src/plugins/importexport/importexportgadgetwidget.ui
Normal file
@ -0,0 +1,94 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ImportExportGadgetWidget</class>
|
||||
<widget class="QWidget" name="ImportExportGadgetWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QLineEdit" name="configFile">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>80</y>
|
||||
<width>251</width>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>80</y>
|
||||
<width>81</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Config File</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
<width>331</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>This is highly experimental. Use at own risk.</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="exportButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>100</x>
|
||||
<y>120</y>
|
||||
<width>83</width>
|
||||
<height>26</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="importButton">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>120</y>
|
||||
<width>88</width>
|
||||
<height>27</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>40</y>
|
||||
<width>331</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Please report bugs!</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
66
ground/src/plugins/importexport/importexportplugin.cpp
Normal file
66
ground/src/plugins/importexport/importexportplugin.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "importexportplugin.h"
|
||||
#include "importexportgadgetfactory.h"
|
||||
#include <QDebug>
|
||||
#include <QtPlugin>
|
||||
#include <QStringList>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
|
||||
ImportExportPlugin::ImportExportPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
ImportExportPlugin::~ImportExportPlugin()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
bool ImportExportPlugin::initialize(const QStringList& args, QString *errMsg)
|
||||
{
|
||||
Q_UNUSED(args);
|
||||
Q_UNUSED(errMsg);
|
||||
mf = new ImportExportGadgetFactory(this);
|
||||
addAutoReleasedObject(mf);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImportExportPlugin::extensionsInitialized()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
void ImportExportPlugin::shutdown()
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
Q_EXPORT_PLUGIN(ImportExportPlugin)
|
||||
|
48
ground/src/plugins/importexport/importexportplugin.h
Normal file
48
ground/src/plugins/importexport/importexportplugin.h
Normal file
@ -0,0 +1,48 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file importexportplugin.h
|
||||
* @author Edouard Lafargue Copyright (C) 2010.
|
||||
* @brief
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup importexportplugin
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef IMPORTEXPORTPLUGIN_H_
|
||||
#define IMPORTEXPORTPLUGIN_H_
|
||||
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include "importexport_global.h"
|
||||
|
||||
class ImportExportGadgetFactory;
|
||||
|
||||
class IMPORTEXPORT_EXPORT ImportExportPlugin : public ExtensionSystem::IPlugin
|
||||
{
|
||||
public:
|
||||
ImportExportPlugin();
|
||||
~ImportExportPlugin();
|
||||
|
||||
void extensionsInitialized();
|
||||
bool initialize(const QStringList & arguments, QString * errorString);
|
||||
void shutdown();
|
||||
private:
|
||||
ImportExportGadgetFactory *mf;
|
||||
};
|
||||
#endif /* IMPORTEXPORTPLUGIN_H_ */
|
@ -142,6 +142,11 @@ plugin_hitlil2.depends += plugin_uavobjects
|
||||
plugin_hitlil2.depends += plugin_uavtalk
|
||||
SUBDIRS += plugin_hitlil2
|
||||
|
||||
# Export and Import GCS Configuration.
|
||||
plugin_importexport.subdir = importexport
|
||||
plugin_importexport.depends = plugin_coreplugin
|
||||
SUBDIRS += plugin_importexport
|
||||
|
||||
#GCS Control of UAV Gadget
|
||||
plugin_gcscontrol.subdir = gcscontrol
|
||||
plugin_gcscontrol.depends = plugin_coreplugin
|
||||
|
Loading…
x
Reference in New Issue
Block a user