1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/coreplugin: Cleanup of uav gadget interface.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@393 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-26 21:04:02 +00:00 committed by ephy
parent 59254ae382
commit 058b261b82
8 changed files with 219 additions and 119 deletions

View File

@ -58,7 +58,8 @@ SOURCES += mainwindow.cpp \
iconnection.cpp \
iuavgadgetconfiguration.cpp \
uavgadgetinstancemanager.cpp \
uavgadgetoptionspagedecorator.cpp
uavgadgetoptionspagedecorator.cpp \
uavgadgetdecorator.cpp
HEADERS += mainwindow.h \
tabpositionindicator.h \
fancyactionbar.h \
@ -113,7 +114,8 @@ HEADERS += mainwindow.h \
iconnection.h \
iuavgadgetconfiguration.h \
uavgadgetinstancemanager.h \
uavgadgetoptionspagedecorator.h
uavgadgetoptionspagedecorator.h \
uavgadgetdecorator.h
FORMS += dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
generalsettings.ui \

View File

@ -26,95 +26,3 @@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "iuavgadget.h"
#include "iuavgadgetconfiguration.h"
using namespace Core;
IUAVGadget::IUAVGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, QObject *parent) :
IContext(parent),
m_toolbar(new QComboBox),
m_classId(classId),
m_activeConfiguration(0),
m_configurations(configurations)
{
m_toolbar->setMinimumContentsLength(15);
foreach (IUAVGadgetConfiguration *config, *m_configurations)
m_toolbar->addItem(config->name());
connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int)));
if (m_configurations->count() > 0)
loadConfiguration(0);
updateToolbar();
}
void IUAVGadget::loadConfiguration(int index) {
IUAVGadgetConfiguration* config = m_configurations->at(index);
m_activeConfiguration = config;
loadConfiguration(config);
}
void IUAVGadget::setActiveConfiguration(IUAVGadgetConfiguration *config)
{
m_activeConfiguration = config;
int index = m_toolbar->findText(config->name());
m_toolbar->setCurrentIndex(index);
}
void IUAVGadget::configurationChanged(IUAVGadgetConfiguration* config)
{
if (config == m_activeConfiguration)
loadConfiguration(config);
}
void IUAVGadget::configurationAdded(IUAVGadgetConfiguration* config)
{
m_configurations->append(config);
m_toolbar->addItem(config->name());
updateToolbar();
}
void IUAVGadget::configurationToBeDeleted(IUAVGadgetConfiguration* config)
{
int index = m_configurations->indexOf(config);
if (index >= 0) {
m_toolbar->removeItem(index);
m_configurations->removeAt(index);
}
updateToolbar();
}
void IUAVGadget::configurationNameChanged(QString oldName, QString newName)
{
for (int i = 0; i < m_toolbar->count(); ++i) {
if (m_toolbar->itemText(i) == oldName)
m_toolbar->setItemText(i, newName);
}
}
void IUAVGadget::updateToolbar()
{
m_toolbar->setEnabled(m_toolbar->count() > 1);
}
QByteArray IUAVGadget::saveState()
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
if (m_activeConfiguration)
stream << m_activeConfiguration->name().toLatin1();
return bytes;
}
void IUAVGadget::restoreState(QByteArray state)
{
QDataStream stream(state);
QByteArray configName;
stream >> configName;
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
if (config->name() == configName) {
m_activeConfiguration = config;
loadConfiguration(config);
}
}
}

View File

@ -46,34 +46,32 @@ class CORE_EXPORT IUAVGadget : public IContext
{
Q_OBJECT
public:
IUAVGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, QObject *parent = 0);
IUAVGadget(QString classId, QObject *parent = 0) :
IContext(parent),
m_classId(classId) { }
virtual ~IUAVGadget() {}
virtual QList<int> context() const = 0;
QList<int> context() const { return m_context; }
void setContext(QList<int> context) { m_context = context; }
virtual QWidget *widget() = 0;
virtual QComboBox *toolBar() { return 0; }
virtual QString contextHelpId() const { return QString(); }
QString classId() const { return m_classId; }
virtual void loadConfiguration(IUAVGadgetConfiguration* /*config*/) { }
IUAVGadgetConfiguration *activeConfiguration() { return m_activeConfiguration; }
void setActiveConfiguration(IUAVGadgetConfiguration *config);
QComboBox *toolBar() { return m_toolbar; }
virtual QByteArray saveState();
virtual void restoreState(QByteArray state);
virtual IUAVGadgetConfiguration *activeConfiguration() { return 0; }
virtual void loadConfiguration(IUAVGadgetConfiguration*) { }
virtual QByteArray saveState() { return QByteArray(); }
virtual void restoreState(QByteArray) { }
public slots:
void configurationChanged(IUAVGadgetConfiguration* config);
void configurationAdded(IUAVGadgetConfiguration* config);
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
void configurationNameChanged(QString oldName, QString newName);
virtual void configurationChanged(IUAVGadgetConfiguration* ) { }
virtual void configurationAdded(IUAVGadgetConfiguration*) { }
virtual void configurationToBeDeleted(IUAVGadgetConfiguration*) { }
virtual void configurationNameChanged(QString, QString) { }
private slots:
void loadConfiguration(int index);
protected:
QComboBox *m_toolbar;
private:
void updateToolbar();
QString m_classId;
IUAVGadgetConfiguration *m_activeConfiguration;
QList<IUAVGadgetConfiguration*> *m_configurations;
QList<int> m_context;
};
} // namespace Core

View File

@ -52,10 +52,10 @@ public:
m_name(name) {}
virtual ~IUAVGadgetFactory() {}
virtual IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent) = 0;
virtual IUAVGadget *createGadget(QWidget *parent) = 0;
virtual IUAVGadgetConfiguration *createConfiguration(bool /*locked*/,
const QString /*configName*/,
const QByteArray &/*state*/) { return 0; }
const QString /*configName*/,
const QByteArray &/*state*/) { return 0; }
virtual IOptionsPage *createOptionsPage(IUAVGadgetConfiguration */*config*/) { return 0; }
QString classId() const { return m_classId; }
QString name() const { return m_name; }

View File

@ -0,0 +1,121 @@
/**
******************************************************************************
*
* @file uavgadgetdecorator.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup coreplugin
* @{
*
*****************************************************************************/
/*
* 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 "uavgadgetdecorator.h"
#include "iuavgadgetconfiguration.h"
#include <QtGui/QComboBox>
#include <QtCore/QByteArray>
using namespace Core;
UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfiguration*> *configurations) :
IUAVGadget(gadget->classId(), gadget->parent()),
m_gadget(gadget),
m_toolbar(new QComboBox),
m_activeConfiguration(0),
m_configurations(configurations)
{
m_toolbar->setMinimumContentsLength(15);
foreach (IUAVGadgetConfiguration *config, *m_configurations)
m_toolbar->addItem(config->name());
connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int)));
if (m_configurations->count() > 0)
loadConfiguration(0);
updateToolbar();
}
void UAVGadgetDecorator::loadConfiguration(int index) {
IUAVGadgetConfiguration* config = m_configurations->at(index);
loadConfiguration(config);
}
void UAVGadgetDecorator::loadConfiguration(IUAVGadgetConfiguration *config)
{
m_activeConfiguration = config;
int index = m_toolbar->findText(config->name());
m_toolbar->setCurrentIndex(index);
m_gadget->loadConfiguration(config);
}
void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration* config)
{
if (config == m_activeConfiguration)
loadConfiguration(config);
}
void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config)
{
m_configurations->append(config);
m_toolbar->addItem(config->name());
updateToolbar();
}
void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* config)
{
int index = m_configurations->indexOf(config);
if (index >= 0) {
m_toolbar->removeItem(index);
m_configurations->removeAt(index);
}
updateToolbar();
}
void UAVGadgetDecorator::configurationNameChanged(QString oldName, QString newName)
{
for (int i = 0; i < m_toolbar->count(); ++i) {
if (m_toolbar->itemText(i) == oldName)
m_toolbar->setItemText(i, newName);
}
}
void UAVGadgetDecorator::updateToolbar()
{
m_toolbar->setEnabled(m_toolbar->count() > 1);
}
QByteArray UAVGadgetDecorator::saveState()
{
QByteArray bytes;
QDataStream stream(&bytes, QIODevice::WriteOnly);
if (m_activeConfiguration)
stream << m_activeConfiguration->name().toLatin1();
return bytes;
}
void UAVGadgetDecorator::restoreState(QByteArray state)
{
QDataStream stream(state);
QByteArray configName;
stream >> configName;
foreach (IUAVGadgetConfiguration *config, *m_configurations) {
if (config->name() == configName) {
m_activeConfiguration = config;
loadConfiguration(config);
}
}
}

View File

@ -0,0 +1,66 @@
/**
******************************************************************************
*
* @file uavgadgetdecorator.h
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @brief
* @see The GNU Public License (GPL) Version 3
* @defgroup coreplugin
* @{
*
*****************************************************************************/
/*
* 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 UAVGADGETDECORATOR_H
#define UAVGADGETDECORATOR_H
#include <coreplugin/iuavgadget.h>
namespace Core {
class IUAVGadgetConfiguration;
class UAVGadgetDecorator : public IUAVGadget
{
Q_OBJECT
public:
explicit UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfiguration*> *configurations);
QWidget *widget() { return m_gadget->widget(); }
QComboBox *toolBar() { return m_toolbar; }
IUAVGadgetConfiguration *activeConfiguration() { return m_activeConfiguration; }
void loadConfiguration(IUAVGadgetConfiguration *config);
QByteArray saveState();
void restoreState(QByteArray state);
public slots:
void configurationChanged(IUAVGadgetConfiguration* config);
void configurationAdded(IUAVGadgetConfiguration* config);
void configurationToBeDeleted(IUAVGadgetConfiguration* config);
void configurationNameChanged(QString oldName, QString newName);
private slots:
void loadConfiguration(int index);
private:
void updateToolbar();
IUAVGadget *m_gadget;
QComboBox *m_toolbar;
IUAVGadgetConfiguration *m_activeConfiguration;
QList<IUAVGadgetConfiguration*> *m_configurations;
};
} // namespace Core
#endif // UAVGADGETDECORATOR_H

View File

@ -27,8 +27,10 @@
#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"
@ -122,7 +124,8 @@ void UAVGadgetInstanceManager::createOptionsPages()
foreach (IUAVGadgetConfiguration *config, m_configurations)
{
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *page = f->createOptionsPage(config);
IOptionsPage *p = f->createOptionsPage(config);
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
m_optionsPages.append(page);
m_pm->addObject(page);
}
@ -134,7 +137,8 @@ IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *par
IUAVGadgetFactory *f = factory(classId);
if (f) {
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
IUAVGadget *gadget = f->createGadget(configs, parent);
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*)));
@ -183,7 +187,8 @@ void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *conf
IUAVGadgetConfiguration *config = configToClone->clone(name);
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *page = f->createOptionsPage(config);
IOptionsPage *p = f->createOptionsPage(config);
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
m_provisionalConfigs.append(config);
m_provisionalOptionsPages.append(page);
m_settingsDialog->insertPage(page);

View File

@ -74,8 +74,8 @@ QWidget *UAVGadgetOptionsPageDecorator::createPage(QWidget *parent)
void UAVGadgetOptionsPageDecorator::apply()
{
m_id = m_config->provisionalName();
m_instanceManager->applyChanges(m_config);
m_optionsPage->apply();
m_instanceManager->applyChanges(m_config);
}
void UAVGadgetOptionsPageDecorator::finish()