From 1e3aeaf988a500a28ff8c84b61bf64d62dc10d28 Mon Sep 17 00:00:00 2001 From: filnet Date: Wed, 16 Jan 2013 23:43:22 +0100 Subject: [PATCH] OP-803 fix attempt --- .../plugins/coreplugin/uavgadgetdecorator.cpp | 4 ++-- .../coreplugin/uavgadgetinstancemanager.cpp | 8 +++++-- .../coreplugin/uavgadgetinstancemanager.h | 2 +- .../uavgadgetmanager/uavgadgetview.cpp | 22 +++++++++++++++++-- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp index fd6d1164e..55d3a9a31 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -45,8 +45,8 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QListaddItem(config->name()); connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int))); - if (m_configurations->count() > 0) - loadConfiguration(0); +// if (m_configurations->count() > 0) +// loadConfiguration(0); updateToolbar(); } diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 55dc239a8..3393dc4b5 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -253,13 +253,17 @@ void UAVGadgetInstanceManager::createOptionsPages() } -IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent) +IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *parent, bool loadDefaultConfiguration) { IUAVGadgetFactory *f = factory(classId); if (f) { QList *configs = configurations(classId); IUAVGadget *g = f->createGadget(parent); - IUAVGadget *gadget = new UAVGadgetDecorator(g, configs); + UAVGadgetDecorator *gadget = new UAVGadgetDecorator(g, configs); + if ((loadDefaultConfiguration && configs && configs->count()) > 0) { + gadget->loadConfiguration(configs->at(0)); + } + m_gadgetInstances.append(gadget); connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*))); connect(this, SIGNAL(configurationChanged(IUAVGadgetConfiguration*)), gadget, SLOT(configurationChanged(IUAVGadgetConfiguration*))); diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h index fab30f284..a67953fc1 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.h @@ -61,7 +61,7 @@ public: ~UAVGadgetInstanceManager(); void readSettings(QSettings *qs); void saveSettings(QSettings *qs); - IUAVGadget *createGadget(QString classId, QWidget *parent); + IUAVGadget *createGadget(QString classId, QWidget *parent, bool loadDefaultConfiguration = true); void removeGadget(IUAVGadget *gadget); void removeAllGadgets(); bool canDeleteConfiguration(IUAVGadgetConfiguration *config); diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp index 6deb3adc9..6fef953d6 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp @@ -265,11 +265,29 @@ void UAVGadgetView::saveState(QSettings* qSettings) void UAVGadgetView::restoreState(QSettings* qSettings) { QString classId = qSettings->value("classId").toString(); + int index = indexOfClassId(classId); - listSelectionActivated(index); + if (index < 0) { + index = m_defaultIndex; + } + + classId = m_uavGadgetList->itemData(index).toString(); + + + IUAVGadget *newGadget; + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); if(qSettings->childGroups().contains("gadget")) { + newGadget = im->createGadget(classId, this, false); qSettings->beginGroup("gadget"); - gadget()->restoreState(qSettings); + newGadget->restoreState(qSettings); qSettings->endGroup(); } + else { + newGadget = im->createGadget(classId, this); + } + + IUAVGadget *gadgetToRemove = m_uavGadget; + setGadget(newGadget); + m_uavGadgetManager->setCurrentGadget(newGadget); + im->removeGadget(gadgetToRemove); }