From 35f4fc06a08d4c4b1384075702d6ad9467c9b2d8 Mon Sep 17 00:00:00 2001 From: ephy Date: Sat, 27 Mar 2010 19:24:21 +0000 Subject: [PATCH] GCS/core+gadgets: Second attempt at cleanup of uav gadget interface. git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@400 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 +- .../plugins/coreplugin/uavgadgetdecorator.cpp | 9 +- .../plugins/coreplugin/uavgadgetdecorator.h | 2 +- .../coreplugin/uavgadgetinstancemanager.cpp | 28 ++++-- .../coreplugin/uavgadgetinstancemanager.h | 3 +- .../uavgadgetmanager/uavgadgetmanager.cpp | 39 +++++--- .../uavgadgetmanager/uavgadgetview.cpp | 24 ++++- .../uavgadgetmanager/uavgadgetview.h | 1 + .../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 +- 23 files changed, 136 insertions(+), 181 deletions(-) diff --git a/ground/src/plugins/coreplugin/coreplugin.pro b/ground/src/plugins/coreplugin/coreplugin.pro index 8993f0276..1cbbee3ed 100644 --- a/ground/src/plugins/coreplugin/coreplugin.pro +++ b/ground/src/plugins/coreplugin/coreplugin.pro @@ -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 \ diff --git a/ground/src/plugins/coreplugin/iuavgadget.cpp b/ground/src/plugins/coreplugin/iuavgadget.cpp index dbc8b8039..b6fbf961c 100644 --- a/ground/src/plugins/coreplugin/iuavgadget.cpp +++ b/ground/src/plugins/coreplugin/iuavgadget.cpp @@ -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 *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 6307d2cda..9efd289ce 100644 --- a/ground/src/plugins/coreplugin/iuavgadget.h +++ b/ground/src/plugins/coreplugin/iuavgadget.h @@ -46,34 +46,32 @@ class CORE_EXPORT IUAVGadget : public IContext { Q_OBJECT public: - IUAVGadget(QString classId, QList *configurations, QObject *parent = 0); + IUAVGadget(QString classId, QObject *parent = 0) : + IContext(parent), + m_classId(classId) { } + virtual ~IUAVGadget() {} - virtual QList context() const = 0; + QList context() const { return m_context; } + void setContext(QList 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 *m_configurations; + QList m_context; }; } // namespace Core diff --git a/ground/src/plugins/coreplugin/iuavgadgetfactory.h b/ground/src/plugins/coreplugin/iuavgadgetfactory.h index f50bf7269..e5e755a11 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(QList *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; } diff --git a/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp index b36c17392..60ca801ee 100644 --- a/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -29,6 +29,7 @@ #include "iuavgadgetconfiguration.h" #include #include +#include using namespace Core; @@ -70,6 +71,8 @@ void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration* config) void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config) { + if (config->classId() != classId()) + return; m_configurations->append(config); m_toolbar->addItem(config->name()); updateToolbar(); @@ -77,6 +80,8 @@ void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config) void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* config) { + if (config->classId() != classId()) + return; int index = m_configurations->indexOf(config); if (index >= 0) { m_toolbar->removeItem(index); @@ -85,8 +90,10 @@ void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* confi updateToolbar(); } -void UAVGadgetDecorator::configurationNameChanged(QString oldName, QString newName) +void UAVGadgetDecorator::configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName) { + if (config->classId() != classId()) + return; for (int i = 0; i < m_toolbar->count(); ++i) { if (m_toolbar->itemText(i) == oldName) m_toolbar->setItemText(i, newName); diff --git a/ground/src/plugins/coreplugin/uavgadgetdecorator.h b/ground/src/plugins/coreplugin/uavgadgetdecorator.h index dfdb46ffd..04a1078d0 100644 --- a/ground/src/plugins/coreplugin/uavgadgetdecorator.h +++ b/ground/src/plugins/coreplugin/uavgadgetdecorator.h @@ -49,7 +49,7 @@ public slots: void configurationChanged(IUAVGadgetConfiguration* config); void configurationAdded(IUAVGadgetConfiguration* config); void configurationToBeDeleted(IUAVGadgetConfiguration* config); - void configurationNameChanged(QString oldName, QString newName); + void configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName); private slots: void loadConfiguration(int index); private: diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 6c2c0a855..86d548912 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -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,17 +137,25 @@ IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *par IUAVGadgetFactory *f = factory(classId); if (f) { QList *configs = configurations(classId); - IUAVGadget *gadget = f->createGadget(configs, parent); + IUAVGadget *g = f->createGadget(0); + 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(QString,QString)), gadget, SLOT(configurationNameChanged(QString,QString))); + 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); + } +} + bool UAVGadgetInstanceManager::canDeleteConfiguration(IUAVGadgetConfiguration *config) { // to be able to delete a configuration, no instance must be using it @@ -183,7 +194,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); @@ -229,7 +241,7 @@ void UAVGadgetInstanceManager::applyChanges(IUAVGadgetConfiguration *config) return; } if (config->provisionalName() != config->name()) { - emit configurationNameChanged(config->name(), config->provisionalName()); + emit configurationNameChanged(config, config->name(), config->provisionalName()); config->setName(config->provisionalName()); } if (m_configurations.contains(config)) { @@ -251,17 +263,17 @@ void UAVGadgetInstanceManager::configurationNameEdited(QString text, bool hasTex bool disable = false; foreach (IUAVGadgetConfiguration *c, m_configurations) { foreach (IUAVGadgetConfiguration *d, m_configurations) { - if (c != d && c->provisionalName() == d->provisionalName()) + if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName()) disable = true; } foreach (IUAVGadgetConfiguration *d, m_provisionalConfigs) { - if (c != d && c->provisionalName() == d->provisionalName()) + 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->provisionalName() == d->provisionalName()) + if (c != d && c->classId() == d->classId() && c->provisionalName() == d->provisionalName()) disable = true; } } diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h index 54b5e2dfa..3daaed19e 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.h @@ -57,6 +57,7 @@ public: 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); @@ -70,7 +71,7 @@ signals: void configurationChanged(IUAVGadgetConfiguration* config); void configurationAdded(IUAVGadgetConfiguration* config); void configurationToBeDeleted(IUAVGadgetConfiguration* config); - void configurationNameChanged(QString oldName, QString newName); + void configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName); public slots: void settingsDialogShown(Core::Internal::SettingsDialog* settingsDialog); diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp index aa90dce7e..a82b8b157 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp @@ -29,6 +29,7 @@ #include "uavgadgetmanager.h" #include "uavgadgetview.h" #include "uavgadgetmode.h" +#include "uavgadgetinstancemanager.h" #include "iuavgadgetfactory.h" #include "iuavgadget.h" #include "icore.h" @@ -300,11 +301,9 @@ void UAVGadgetManager::handleContextChange(Core::IContext *context) // if (debugUAVGadgetManager) // qDebug() << Q_FUNC_INFO << context; IUAVGadget *uavGadget = context ? qobject_cast(context) : 0; - if (uavGadget) { + if (uavGadget) setCurrentGadget(uavGadget); - } else { - updateActions(); - } + updateActions(); } void UAVGadgetManager::setCurrentGadget(IUAVGadget *uavGadget) @@ -368,6 +367,10 @@ void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view) if (splitterOrView == m_d->m_splitterOrView) return; + IUAVGadget *gadget = view->gadget(); + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); + im->removeGadget(gadget); + emptyView(view); SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView); @@ -382,23 +385,22 @@ void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view) Q_ASSERT(newCurrent); if (newCurrent) setCurrentGadget(newCurrent->gadget()); - updateActions(); } -void UAVGadgetManager::addGadgetToContext(IUAVGadget *uavGadget) +void UAVGadgetManager::addGadgetToContext(IUAVGadget *gadget) { - if (!uavGadget) + if (!gadget) return; - m_d->m_core->addContextObject(uavGadget); + m_d->m_core->addContextObject(gadget); // emit uavGadgetOpened(uavGadget); } -void UAVGadgetManager::removeGadget(IUAVGadget *uavGadget) +void UAVGadgetManager::removeGadget(IUAVGadget *gadget) { - if (!uavGadget) + if (!gadget) return; - m_d->m_core->removeContextObject(qobject_cast(uavGadget)); + m_d->m_core->removeContextObject(qobject_cast(gadget)); } void UAVGadgetManager::ensureUAVGadgetManagerVisible() @@ -409,6 +411,8 @@ void UAVGadgetManager::ensureUAVGadgetManagerVisible() void UAVGadgetManager::updateActions() { + if (m_d->m_core->modeManager()->currentMode() != m_uavGadgetMode) + return; if (!m_d->m_splitterOrView) // this is only for startup return; // Splitting is only possible when the toolbars are shown @@ -436,6 +440,9 @@ QByteArray UAVGadgetManager::saveState() const bool UAVGadgetManager::restoreState(const QByteArray &state) { removeAllSplits(); + + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); + im->removeGadget(m_d->m_splitterOrView->view()->gadget()); emptyView(m_d->m_splitterOrView->view()); QDataStream stream(state); @@ -454,7 +461,6 @@ bool UAVGadgetManager::restoreState(const QByteArray &state) m_d->m_splitterOrView->restoreState(splitterstates); QApplication::restoreOverrideCursor(); - return true; } @@ -505,7 +511,6 @@ void UAVGadgetManager::split(Qt::Orientation orientation) SplitterOrView *sor = m_d->m_splitterOrView->findView(uavGadget); SplitterOrView *next = m_d->m_splitterOrView->findNextView(sor); setCurrentGadget(next->gadget()); - updateActions(); } void UAVGadgetManager::split() @@ -527,7 +532,6 @@ void UAVGadgetManager::removeCurrentSplit() if (viewToClose == m_d->m_splitterOrView) return; closeView(viewToClose->view()); - updateActions(); } void UAVGadgetManager::removeAllSplits() @@ -538,6 +542,13 @@ void UAVGadgetManager::removeAllSplits() if (!m_d->m_splitterOrView->isSplitter()) return; IUAVGadget *uavGadget = m_d->m_currentGadget; + QList gadgets = m_d->m_splitterOrView->gadgets(); + gadgets.removeOne(uavGadget); + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); + foreach (IUAVGadget *g, gadgets) { + im->removeGadget(g); + } + m_d->m_currentGadget = 0; // trigger update below m_d->m_splitterOrView->unsplitAll(); m_d->m_splitterOrView->view()->setGadget(uavGadget); diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp index 5614ecd1c..e23a6c0cd 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp @@ -217,11 +217,12 @@ void UAVGadgetView::listSelectionActivated(int index) { if (index < 0) // this could happen when called from SplitterOrView::restoreState() index = m_defaultIndex; - UAVGadgetInstanceManager *fm = ICore::instance()->uavGadgetInstanceManager(); QString classId = m_uavGadgetList->itemData(index).toString(); if (m_uavGadget && (m_uavGadget->classId() == classId)) return; - IUAVGadget *gadget = fm->createGadget(classId, this); + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); + im->removeGadget(m_uavGadget); + IUAVGadget *gadget = im->createGadget(classId, this); setGadget(gadget); m_uavGadgetManager->setCurrentGadget(gadget); } @@ -460,6 +461,22 @@ UAVGadgetView *SplitterOrView::takeView() return oldView; } +QList SplitterOrView::gadgets() +{ + QList g; + if (hasGadget()) + g.append(gadget()); + if (m_splitter) { + for (int i = 0; i < m_splitter->count(); ++i) { + if (SplitterOrView *splitterOrView = qobject_cast(m_splitter->widget(i))) { + QList result = splitterOrView->gadgets(); + g.append(result); + } + } + } + return g; +} + void SplitterOrView::split(Qt::Orientation orientation) { Q_ASSERT(m_view && (m_splitter == 0)); @@ -579,11 +596,8 @@ void SplitterOrView::restoreState(const QByteArray &state) QString classId; QByteArray uavGadgetState; stream >> classId >> uavGadgetState; - m_view = new UAVGadgetView(m_uavGadgetManager, 0); int index = m_view->indexOfClassId(classId); m_view->listSelectionActivated(index); - m_layout->addWidget(m_view); - m_layout->setCurrentWidget(m_view); gadget()->restoreState(uavGadgetState); } } diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h index 990a9b45c..663606426 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.h @@ -117,6 +117,7 @@ public: inline bool hasGadget() const { return m_view && (m_view->gadget() != 0); } inline UAVGadgetView *view() const { return m_view; } inline QSplitter *splitter() const { return m_splitter; } + QList gadgets(); QSplitter *takeSplitter(); UAVGadgetView *takeView(); diff --git a/ground/src/plugins/emptygadget/emptygadget.cpp b/ground/src/plugins/emptygadget/emptygadget.cpp index e48b624a6..7278024bc 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, QList *configurations, EmptyGadgetWidget *widget) : - IUAVGadget(classId, configurations, widget), +EmptyGadget::EmptyGadget(QString classId, EmptyGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), m_widget(widget) { } diff --git a/ground/src/plugins/emptygadget/emptygadget.h b/ground/src/plugins/emptygadget/emptygadget.h index 08b2cf14a..7c620d527 100644 --- a/ground/src/plugins/emptygadget/emptygadget.h +++ b/ground/src/plugins/emptygadget/emptygadget.h @@ -30,9 +30,11 @@ #include +namespace Core { class IUAVGadget; -class QWidget; -class QString; +} +//class QWidget; +//class QString; class EmptyGadgetWidget; using namespace Core; @@ -41,7 +43,7 @@ class EmptyGadget : public Core::IUAVGadget { Q_OBJECT public: - EmptyGadget(QString classId, QList *configurations, EmptyGadgetWidget *widget = 0); + EmptyGadget(QString classId, EmptyGadgetWidget *widget, QWidget *parent = 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 9f96f2a30..1206509e9 100644 --- a/ground/src/plugins/emptygadget/emptygadgetfactory.cpp +++ b/ground/src/plugins/emptygadget/emptygadgetfactory.cpp @@ -41,7 +41,7 @@ EmptyGadgetFactory::~EmptyGadgetFactory() } -Core::IUAVGadget* EmptyGadgetFactory::createGadget(QList *configurations, QWidget *parent) { - EmptyGadgetWidget* gadgetWidget = new EmptyGadgetWidget(parent); - return new EmptyGadget(QString("EmptyGadget"), configurations, gadgetWidget); +IUAVGadget* EmptyGadgetFactory::createGadget(QWidget *parent) { + EmptyGadgetWidget* gadgetWidget = new EmptyGadgetWidget(parent); + return new EmptyGadget(QString("EmptyGadget"), gadgetWidget, parent); } diff --git a/ground/src/plugins/emptygadget/emptygadgetfactory.h b/ground/src/plugins/emptygadget/emptygadgetfactory.h index d652e3cc7..93451a6f4 100644 --- a/ground/src/plugins/emptygadget/emptygadgetfactory.h +++ b/ground/src/plugins/emptygadget/emptygadgetfactory.h @@ -30,18 +30,21 @@ #include -using namespace Core; +namespace Core { class IUAVGadget; class IUAVGadgetFactory; +} -class EmptyGadgetFactory : public Core::IUAVGadgetFactory +using namespace Core; + +class EmptyGadgetFactory : public IUAVGadgetFactory { Q_OBJECT public: EmptyGadgetFactory(QObject *parent = 0); ~EmptyGadgetFactory(); - Core::IUAVGadget *createGadget(QList *configurations, QWidget *parent); + IUAVGadget *createGadget(QWidget *parent); }; #endif // EMPTYGADGETFACTORY_H_ diff --git a/ground/src/plugins/map/mapgadget.cpp b/ground/src/plugins/map/mapgadget.cpp index 4d11746e1..2ee7d1911 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, QList *configurations, MapGadgetWidget *widget) : - IUAVGadget(classId, configurations, widget), +MapGadget::MapGadget(QString classId, MapGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), m_widget(widget) { } @@ -41,8 +41,6 @@ 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 8f372af77..eedaec42b 100644 --- a/ground/src/plugins/map/mapgadget.h +++ b/ground/src/plugins/map/mapgadget.h @@ -43,17 +43,14 @@ class MapGadget : public Core::IUAVGadget { Q_OBJECT public: - MapGadget(QString classId, QList *configurations, MapGadgetWidget *widget = 0); + MapGadget(QString classId, MapGadgetWidget *widget, QWidget *parent = 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; - QList m_context; + MapGadgetWidget *m_widget; }; diff --git a/ground/src/plugins/map/mapgadgetfactory.cpp b/ground/src/plugins/map/mapgadgetfactory.cpp index 695216bef..2ec3e510d 100644 --- a/ground/src/plugins/map/mapgadgetfactory.cpp +++ b/ground/src/plugins/map/mapgadgetfactory.cpp @@ -29,7 +29,6 @@ #include "mapgadget.h" #include "mapgadgetconfiguration.h" #include "mapgadgetoptionspage.h" -#include #include MapGadgetFactory::MapGadgetFactory(QObject *parent) : @@ -41,10 +40,10 @@ MapGadgetFactory::~MapGadgetFactory() { } -Core::IUAVGadget* MapGadgetFactory::createGadget(QList *configurations, QWidget *parent) +Core::IUAVGadget* MapGadgetFactory::createGadget(QWidget *parent) { - MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent); - return new MapGadget(QString("MapGadget"), configurations, gadgetWidget); + MapGadgetWidget* gadgetWidget = new MapGadgetWidget(parent); + return new MapGadget(QString("MapGadget"), gadgetWidget, parent); } IUAVGadgetConfiguration *MapGadgetFactory::createConfiguration(bool locked, @@ -56,7 +55,6 @@ IUAVGadgetConfiguration *MapGadgetFactory::createConfiguration(bool locked, IOptionsPage *MapGadgetFactory::createOptionsPage(IUAVGadgetConfiguration *config) { - MapGadgetOptionsPage *page = new MapGadgetOptionsPage(config); - return new UAVGadgetOptionsPageDecorator(page, config); + return new MapGadgetOptionsPage(config); } diff --git a/ground/src/plugins/map/mapgadgetfactory.h b/ground/src/plugins/map/mapgadgetfactory.h index 0fce3fa15..640dcc5ea 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(QList *configurations, QWidget *parent); + Core::IUAVGadget *createGadget(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 5a40558a5..15ff5d870 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, QList *configurations, ScopeGadgetWidget *widget) : - IUAVGadget(classId, configurations, widget), +ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) : + IUAVGadget(classId, parent), m_widget(widget) { } diff --git a/ground/src/plugins/scope/scopegadget.h b/ground/src/plugins/scope/scopegadget.h index 08509c0b7..c5a15d3aa 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, QList *configurations, ScopeGadgetWidget *widget = 0); + ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent = 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 b4d3d7814..b093fc380 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(QList *configurations, QWidget *parent) { - ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent); - return new ScopeGadget(QString("ScopeGadget"), configurations, gadgetWidget); +Core::IUAVGadget* ScopeGadgetFactory::createGadget(QWidget *parent) { + ScopeGadgetWidget* gadgetWidget = new ScopeGadgetWidget(parent); + return new ScopeGadget(QString("ScopeGadget"), gadgetWidget, parent); } diff --git a/ground/src/plugins/scope/scopegadgetfactory.h b/ground/src/plugins/scope/scopegadgetfactory.h index 53bbba91e..a2c1e3e6b 100644 --- a/ground/src/plugins/scope/scopegadgetfactory.h +++ b/ground/src/plugins/scope/scopegadgetfactory.h @@ -10,18 +10,21 @@ #include -using namespace Core; +namespace Core { class IUAVGadget; class IUAVGadgetFactory; +} -class ScopeGadgetFactory : public Core::IUAVGadgetFactory +using namespace Core; + +class ScopeGadgetFactory : public IUAVGadgetFactory { Q_OBJECT public: ScopeGadgetFactory(QObject *parent = 0); ~ScopeGadgetFactory(); - Core::IUAVGadget *createGadget(QList *configurations, QWidget *parent); + IUAVGadget *createGadget(QWidget *parent); }; #endif // SCOPEGADGETFACTORY_H_