From 7c860c19c1287033e42b4753a0126c1007b93a85 Mon Sep 17 00:00:00 2001 From: ephy Date: Fri, 26 Mar 2010 22:38:01 +0000 Subject: [PATCH] GCS/coreplugin: Reversal of rev 393-394. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@395 ebee16cc-31ac-478f-84a7-5cbb03baadba --- ground/src/plugins/coreplugin/coreplugin.pro | 6 +- ground/src/plugins/coreplugin/iuavgadget.cpp | 92 +++++++++++++++++++ ground/src/plugins/coreplugin/iuavgadget.h | 34 +++---- .../plugins/coreplugin/iuavgadgetfactory.h | 6 +- .../coreplugin/uavgadgetinstancemanager.cpp | 11 +-- .../uavgadgetoptionspagedecorator.cpp | 2 +- .../src/plugins/emptygadget/emptygadget.cpp | 4 +- ground/src/plugins/emptygadget/emptygadget.h | 8 +- .../emptygadget/emptygadgetfactory.cpp | 6 +- .../plugins/emptygadget/emptygadgetfactory.h | 9 +- ground/src/plugins/map/mapgadget.cpp | 6 +- ground/src/plugins/map/mapgadget.h | 7 +- ground/src/plugins/map/mapgadgetfactory.cpp | 10 +- ground/src/plugins/map/mapgadgetfactory.h | 2 +- ground/src/plugins/scope/scopegadget.cpp | 4 +- ground/src/plugins/scope/scopegadget.h | 2 +- .../src/plugins/scope/scopegadgetfactory.cpp | 6 +- ground/src/plugins/scope/scopegadgetfactory.h | 9 +- 18 files changed, 155 insertions(+), 69 deletions(-) diff --git a/ground/src/plugins/coreplugin/coreplugin.pro b/ground/src/plugins/coreplugin/coreplugin.pro index 1cbbee3ed..8993f0276 100644 --- a/ground/src/plugins/coreplugin/coreplugin.pro +++ b/ground/src/plugins/coreplugin/coreplugin.pro @@ -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 \ diff --git a/ground/src/plugins/coreplugin/iuavgadget.cpp b/ground/src/plugins/coreplugin/iuavgadget.cpp index b6fbf961c..dbc8b8039 100644 --- a/ground/src/plugins/coreplugin/iuavgadget.cpp +++ b/ground/src/plugins/coreplugin/iuavgadget.cpp @@ -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 *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); + } + } +} diff --git a/ground/src/plugins/coreplugin/iuavgadget.h b/ground/src/plugins/coreplugin/iuavgadget.h index 9efd289ce..6307d2cda 100644 --- a/ground/src/plugins/coreplugin/iuavgadget.h +++ b/ground/src/plugins/coreplugin/iuavgadget.h @@ -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 *configurations, QObject *parent = 0); virtual ~IUAVGadget() {} - QList context() const { return m_context; } - void setContext(QList context) { m_context = context; } + virtual QList 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 m_context; + IUAVGadgetConfiguration *m_activeConfiguration; + QList *m_configurations; }; } // namespace Core diff --git a/ground/src/plugins/coreplugin/iuavgadgetfactory.h b/ground/src/plugins/coreplugin/iuavgadgetfactory.h index e5e755a11..f50bf7269 100644 --- a/ground/src/plugins/coreplugin/iuavgadgetfactory.h +++ b/ground/src/plugins/coreplugin/iuavgadgetfactory.h @@ -52,10 +52,10 @@ public: m_name(name) {} virtual ~IUAVGadgetFactory() {} - virtual IUAVGadget *createGadget(QWidget *parent) = 0; + virtual IUAVGadget *createGadget(QList *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; } diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 7c72dd5c9..6c2c0a855 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -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 *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); diff --git a/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp b/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp index db36108a0..1e815c2a6 100644 --- a/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp @@ -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() diff --git a/ground/src/plugins/emptygadget/emptygadget.cpp b/ground/src/plugins/emptygadget/emptygadget.cpp index 7278024bc..e48b624a6 100644 --- a/ground/src/plugins/emptygadget/emptygadget.cpp +++ b/ground/src/plugins/emptygadget/emptygadget.cpp @@ -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 *configurations, EmptyGadgetWidget *widget) : + IUAVGadget(classId, configurations, widget), m_widget(widget) { } diff --git a/ground/src/plugins/emptygadget/emptygadget.h b/ground/src/plugins/emptygadget/emptygadget.h index 7c620d527..08b2cf14a 100644 --- a/ground/src/plugins/emptygadget/emptygadget.h +++ b/ground/src/plugins/emptygadget/emptygadget.h @@ -30,11 +30,9 @@ #include -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 *configurations, EmptyGadgetWidget *widget = 0); ~EmptyGadget(); QList context() const { return m_context; } diff --git a/ground/src/plugins/emptygadget/emptygadgetfactory.cpp b/ground/src/plugins/emptygadget/emptygadgetfactory.cpp index 1206509e9..9f96f2a30 100644 --- a/ground/src/plugins/emptygadget/emptygadgetfactory.cpp +++ b/ground/src/plugins/emptygadget/emptygadgetfactory.cpp @@ -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 *configurations, QWidget *parent) { + EmptyGadgetWidget* gadgetWidget = new EmptyGadgetWidget(parent); + return new EmptyGadget(QString("EmptyGadget"), configurations, gadgetWidget); } diff --git a/ground/src/plugins/emptygadget/emptygadgetfactory.h b/ground/src/plugins/emptygadget/emptygadgetfactory.h index 93451a6f4..d652e3cc7 100644 --- a/ground/src/plugins/emptygadget/emptygadgetfactory.h +++ b/ground/src/plugins/emptygadget/emptygadgetfactory.h @@ -30,21 +30,18 @@ #include -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 *configurations, QWidget *parent); }; #endif // EMPTYGADGETFACTORY_H_ diff --git a/ground/src/plugins/map/mapgadget.cpp b/ground/src/plugins/map/mapgadget.cpp index 2ee7d1911..4d11746e1 100644 --- a/ground/src/plugins/map/mapgadget.cpp +++ b/ground/src/plugins/map/mapgadget.cpp @@ -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 *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(config); m_widget->setZoom(m->zoom()); m_widget->setPosition(QPointF(m->longitude(), m->latitude())); diff --git a/ground/src/plugins/map/mapgadget.h b/ground/src/plugins/map/mapgadget.h index eedaec42b..8f372af77 100644 --- a/ground/src/plugins/map/mapgadget.h +++ b/ground/src/plugins/map/mapgadget.h @@ -43,14 +43,17 @@ class MapGadget : public Core::IUAVGadget { Q_OBJECT public: - MapGadget(QString classId, MapGadgetWidget *widget, QWidget *parent = 0); + MapGadget(QString classId, QList *configurations, MapGadgetWidget *widget = 0); ~MapGadget(); + QList 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 m_context; }; diff --git a/ground/src/plugins/map/mapgadgetfactory.cpp b/ground/src/plugins/map/mapgadgetfactory.cpp index 2ec3e510d..695216bef 100644 --- a/ground/src/plugins/map/mapgadgetfactory.cpp +++ b/ground/src/plugins/map/mapgadgetfactory.cpp @@ -29,6 +29,7 @@ #include "mapgadget.h" #include "mapgadgetconfiguration.h" #include "mapgadgetoptionspage.h" +#include #include MapGadgetFactory::MapGadgetFactory(QObject *parent) : @@ -40,10 +41,10 @@ MapGadgetFactory::~MapGadgetFactory() { } -Core::IUAVGadget* MapGadgetFactory::createGadget(QWidget *parent) +Core::IUAVGadget* MapGadgetFactory::createGadget(QList *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); } diff --git a/ground/src/plugins/map/mapgadgetfactory.h b/ground/src/plugins/map/mapgadgetfactory.h index 640dcc5ea..0fce3fa15 100644 --- a/ground/src/plugins/map/mapgadgetfactory.h +++ b/ground/src/plugins/map/mapgadgetfactory.h @@ -44,7 +44,7 @@ public: MapGadgetFactory(QObject *parent = 0); ~MapGadgetFactory(); - Core::IUAVGadget *createGadget(QWidget *parent); + Core::IUAVGadget *createGadget(QList *configurations, QWidget *parent); IUAVGadgetConfiguration *createConfiguration(bool locked, const QString configName, const QByteArray &state); diff --git a/ground/src/plugins/scope/scopegadget.cpp b/ground/src/plugins/scope/scopegadget.cpp index 15ff5d870..5a40558a5 100644 --- a/ground/src/plugins/scope/scopegadget.cpp +++ b/ground/src/plugins/scope/scopegadget.cpp @@ -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 *configurations, ScopeGadgetWidget *widget) : + IUAVGadget(classId, configurations, widget), m_widget(widget) { } diff --git a/ground/src/plugins/scope/scopegadget.h b/ground/src/plugins/scope/scopegadget.h index c5a15d3aa..08509c0b7 100644 --- a/ground/src/plugins/scope/scopegadget.h +++ b/ground/src/plugins/scope/scopegadget.h @@ -22,7 +22,7 @@ class ScopeGadget : public Core::IUAVGadget { Q_OBJECT public: - ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent = 0); + ScopeGadget(QString classId, QList *configurations, ScopeGadgetWidget *widget = 0); ~ScopeGadget(); QList context() const { return m_context; } diff --git a/ground/src/plugins/scope/scopegadgetfactory.cpp b/ground/src/plugins/scope/scopegadgetfactory.cpp index b093fc380..b4d3d7814 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.cpp +++ b/ground/src/plugins/scope/scopegadgetfactory.cpp @@ -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 *configurations, QWidget *parent) { + ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent); + return new ScopeGadget(QString("ScopeGadget"), configurations, gadgetWidget); } diff --git a/ground/src/plugins/scope/scopegadgetfactory.h b/ground/src/plugins/scope/scopegadgetfactory.h index a2c1e3e6b..53bbba91e 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.h +++ b/ground/src/plugins/scope/scopegadgetfactory.h @@ -10,21 +10,18 @@ #include -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 *configurations, QWidget *parent); }; #endif // SCOPEGADGETFACTORY_H_