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

GCS/coreplugin: Reversal of rev 393-394.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@395 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-03-26 22:38:01 +00:00 committed by ephy
parent d642b4a012
commit 7c860c19c1
18 changed files with 155 additions and 69 deletions

View File

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

View File

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

View File

@ -52,10 +52,10 @@ public:
m_name(name) {}
virtual ~IUAVGadgetFactory() {}
virtual IUAVGadget *createGadget(QWidget *parent) = 0;
virtual IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, 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

@ -27,10 +27,8 @@
#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"
@ -124,8 +122,7 @@ void UAVGadgetInstanceManager::createOptionsPages()
foreach (IUAVGadgetConfiguration *config, m_configurations)
{
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *p = f->createOptionsPage(config);
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
IOptionsPage *page = f->createOptionsPage(config);
m_optionsPages.append(page);
m_pm->addObject(page);
}
@ -137,8 +134,7 @@ IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *par
IUAVGadgetFactory *f = factory(classId);
if (f) {
QList<IUAVGadgetConfiguration*> *configs = configurations(classId);
IUAVGadget *g = f->createGadget(parent);
IUAVGadget *gadget = new UAVGadgetDecorator(g, configs);
IUAVGadget *gadget = f->createGadget(configs, parent);
m_gadgetInstances.append(gadget);
connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*)));
connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*)));
@ -187,8 +183,7 @@ void UAVGadgetInstanceManager::cloneConfiguration(IUAVGadgetConfiguration *conf
IUAVGadgetConfiguration *config = configToClone->clone(name);
IUAVGadgetFactory *f = factory(config->classId());
IOptionsPage *p = f->createOptionsPage(config);
IOptionsPage *page = new UAVGadgetOptionsPageDecorator(p, config);
IOptionsPage *page = f->createOptionsPage(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_optionsPage->apply();
m_instanceManager->applyChanges(m_config);
m_optionsPage->apply();
}
void UAVGadgetOptionsPageDecorator::finish()

View File

@ -27,8 +27,8 @@
#include "emptygadget.h"
#include "emptygadgetwidget.h"
EmptyGadget::EmptyGadget(QString classId, EmptyGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
EmptyGadget::EmptyGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, EmptyGadgetWidget *widget) :
IUAVGadget(classId, configurations, widget),
m_widget(widget)
{
}

View File

@ -30,11 +30,9 @@
#include <coreplugin/iuavgadget.h>
namespace Core {
class IUAVGadget;
}
//class QWidget;
//class QString;
class QWidget;
class QString;
class EmptyGadgetWidget;
using namespace Core;
@ -43,7 +41,7 @@ class EmptyGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
EmptyGadget(QString classId, EmptyGadgetWidget *widget, QWidget *parent = 0);
EmptyGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, EmptyGadgetWidget *widget = 0);
~EmptyGadget();
QList<int> context() const { return m_context; }

View File

@ -41,7 +41,7 @@ EmptyGadgetFactory::~EmptyGadgetFactory()
}
IUAVGadget* EmptyGadgetFactory::createGadget(QWidget *parent) {
EmptyGadgetWidget* gadgetWidget = new EmptyGadgetWidget(parent);
return new EmptyGadget(QString("EmptyGadget"), gadgetWidget, parent);
Core::IUAVGadget* EmptyGadgetFactory::createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent) {
EmptyGadgetWidget* gadgetWidget = new EmptyGadgetWidget(parent);
return new EmptyGadget(QString("EmptyGadget"), configurations, gadgetWidget);
}

View File

@ -30,21 +30,18 @@
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
using namespace Core;
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class EmptyGadgetFactory : public IUAVGadgetFactory
class EmptyGadgetFactory : public Core::IUAVGadgetFactory
{
Q_OBJECT
public:
EmptyGadgetFactory(QObject *parent = 0);
~EmptyGadgetFactory();
IUAVGadget *createGadget(QWidget *parent);
Core::IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent);
};
#endif // EMPTYGADGETFACTORY_H_

View File

@ -28,8 +28,8 @@
#include "mapgadgetwidget.h"
#include "mapgadgetconfiguration.h"
MapGadget::MapGadget(QString classId, MapGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
MapGadget::MapGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, MapGadgetWidget *widget) :
IUAVGadget(classId, configurations, widget),
m_widget(widget)
{
}
@ -41,6 +41,8 @@ MapGadget::~MapGadget()
void MapGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
setActiveConfiguration(config);
MapGadgetConfiguration *m = qobject_cast<MapGadgetConfiguration*>(config);
m_widget->setZoom(m->zoom());
m_widget->setPosition(QPointF(m->longitude(), m->latitude()));

View File

@ -43,14 +43,17 @@ class MapGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
MapGadget(QString classId, MapGadgetWidget *widget, QWidget *parent = 0);
MapGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, MapGadgetWidget *widget = 0);
~MapGadget();
QList<int> context() const { return m_context; }
QWidget *widget() { return m_widget; }
QString contextHelpId() const { return QString(); }
void loadConfiguration(IUAVGadgetConfiguration* config);
private:
MapGadgetWidget *m_widget;
MapGadgetWidget *m_widget;
QList<int> m_context;
};

View File

@ -29,6 +29,7 @@
#include "mapgadget.h"
#include "mapgadgetconfiguration.h"
#include "mapgadgetoptionspage.h"
#include <coreplugin/uavgadgetoptionspagedecorator.h>
#include <coreplugin/iuavgadget.h>
MapGadgetFactory::MapGadgetFactory(QObject *parent) :
@ -40,10 +41,10 @@ MapGadgetFactory::~MapGadgetFactory()
{
}
Core::IUAVGadget* MapGadgetFactory::createGadget(QWidget *parent)
Core::IUAVGadget* MapGadgetFactory::createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent)
{
MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent);
return new MapGadget(QString("MapGadget"), gadgetWidget, parent);
MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent);
return new MapGadget(QString("MapGadget"), configurations, gadgetWidget);
}
IUAVGadgetConfiguration *MapGadgetFactory::createConfiguration(bool locked,
@ -55,6 +56,7 @@ IUAVGadgetConfiguration *MapGadgetFactory::createConfiguration(bool locked,
IOptionsPage *MapGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config)
{
return new MapGadgetOptionsPage(config);
MapGadgetOptionsPage *page = new MapGadgetOptionsPage(config);
return new UAVGadgetOptionsPageDecorator(page, config);
}

View File

@ -44,7 +44,7 @@ public:
MapGadgetFactory(QObject *parent = 0);
~MapGadgetFactory();
Core::IUAVGadget *createGadget(QWidget *parent);
Core::IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent);
IUAVGadgetConfiguration *createConfiguration(bool locked,
const QString configName,
const QByteArray &state);

View File

@ -7,8 +7,8 @@
#include "scopegadget.h"
#include "scopegadgetwidget.h"
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
IUAVGadget(classId, parent),
ScopeGadget::ScopeGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, ScopeGadgetWidget *widget) :
IUAVGadget(classId, configurations, widget),
m_widget(widget)
{
}

View File

@ -22,7 +22,7 @@ class ScopeGadget : public Core::IUAVGadget
{
Q_OBJECT
public:
ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent = 0);
ScopeGadget(QString classId, QList<IUAVGadgetConfiguration*> *configurations, ScopeGadgetWidget *widget = 0);
~ScopeGadget();
QList<int> context() const { return m_context; }

View File

@ -21,7 +21,7 @@ ScopeGadgetFactory::~ScopeGadgetFactory()
}
Core::IUAVGadget* ScopeGadgetFactory::createGadget(QWidget *parent) {
ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent);
return new ScopeGadget(QString("ScopeGadget"), gadgetWidget, parent);
Core::IUAVGadget* ScopeGadgetFactory::createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent) {
ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent);
return new ScopeGadget(QString("ScopeGadget"), configurations, gadgetWidget);
}

View File

@ -10,21 +10,18 @@
#include <coreplugin/iuavgadgetfactory.h>
namespace Core {
using namespace Core;
class IUAVGadget;
class IUAVGadgetFactory;
}
using namespace Core;
class ScopeGadgetFactory : public IUAVGadgetFactory
class ScopeGadgetFactory : public Core::IUAVGadgetFactory
{
Q_OBJECT
public:
ScopeGadgetFactory(QObject *parent = 0);
~ScopeGadgetFactory();
IUAVGadget *createGadget(QWidget *parent);
Core::IUAVGadget *createGadget(QList<IUAVGadgetConfiguration*> *configurations, QWidget *parent);
};
#endif // SCOPEGADGETFACTORY_H_