From 3e9c81985001115536fbf2d4a55fbf1fc14c245d Mon Sep 17 00:00:00 2001 From: filnet Date: Mon, 28 Jan 2013 23:13:47 +0100 Subject: [PATCH] OP-803 more cleanups --- .../plugins/coreplugin/uavgadgetdecorator.cpp | 16 +++++++--------- .../coreplugin/uavgadgetinstancemanager.cpp | 13 +++++++++++-- .../uavgadgetmanager/uavgadgetview.cpp | 3 +++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp index 9857831c0..78a98a210 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -45,8 +45,6 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QListaddItem(config->name()); connect(m_toolbar, SIGNAL(activated(int)), this, SLOT(loadConfiguration(int))); -// if (m_configurations->count() > 0) -// loadConfiguration(0); updateToolbar(); } @@ -57,7 +55,7 @@ UAVGadgetDecorator::~UAVGadgetDecorator() } void UAVGadgetDecorator::loadConfiguration(int index) { - IUAVGadgetConfiguration* config = m_configurations->at(index); + IUAVGadgetConfiguration *config = m_configurations->at(index); loadConfiguration(config); } @@ -70,13 +68,13 @@ void UAVGadgetDecorator::loadConfiguration(IUAVGadgetConfiguration *config) } -void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration* config) +void UAVGadgetDecorator::configurationChanged(IUAVGadgetConfiguration *config) { if (config == m_activeConfiguration) loadConfiguration(config); } -void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config) +void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration *config) { if (config->classId() != classId()) return; @@ -85,7 +83,7 @@ void UAVGadgetDecorator::configurationAdded(IUAVGadgetConfiguration* config) updateToolbar(); } -void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* config) +void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration *config) { if (config->classId() != classId()) return; @@ -97,7 +95,7 @@ void UAVGadgetDecorator::configurationToBeDeleted(IUAVGadgetConfiguration* confi updateToolbar(); } -void UAVGadgetDecorator::configurationNameChanged(IUAVGadgetConfiguration* config, QString oldName, QString newName) +void UAVGadgetDecorator::configurationNameChanged(IUAVGadgetConfiguration *config, QString oldName, QString newName) { if (config->classId() != classId()) return; @@ -112,14 +110,14 @@ void UAVGadgetDecorator::updateToolbar() m_toolbar->setEnabled(m_toolbar->count() > 1); } -void UAVGadgetDecorator::saveState(QSettings* qSettings) +void UAVGadgetDecorator::saveState(QSettings *qSettings) { if (m_activeConfiguration) { qSettings->setValue("activeConfiguration", m_activeConfiguration->name()); } } -void UAVGadgetDecorator::restoreState(QSettings* qSettings) +void UAVGadgetDecorator::restoreState(QSettings *qSettings) { QString configName = qSettings->value("activeConfiguration").toString(); foreach (IUAVGadgetConfiguration *config, *m_configurations) { diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 3393dc4b5..a20612c59 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -239,8 +239,9 @@ void UAVGadgetInstanceManager::createOptionsPages() m_pm->removeObject(m_optionsPages.takeLast()); } - foreach (IUAVGadgetConfiguration *config, m_configurations) - { + QMutableListIterator ite(m_configurations); + while (ite.hasNext()) { + IUAVGadgetConfiguration *config = ite.next(); IUAVGadgetFactory *f = factory(config->classId()); IOptionsPage *p = f->createOptionsPage(config); if (p) { @@ -249,6 +250,14 @@ void UAVGadgetInstanceManager::createOptionsPages() m_optionsPages.append(page); m_pm->addObject(page); } + else { + qWarning() + << "UAVGadgetInstanceManager::createOptionsPages - failed to create options page for configuration " + + config->classId() + ":" + config->name() + ", configuration will be removed."; + // The m_optionsPages list and m_configurations list must be in synch otherwise nasty issues happen later + // so if we fail to create an options page we must remove the associated configuration + ite.remove(); + } } } diff --git a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp index 3cf7a0387..5a380c576 100644 --- a/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp +++ b/ground/openpilotgcs/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp @@ -230,6 +230,9 @@ void UAVGadgetView::updateToolBar() void UAVGadgetView::listSelectionActivated(int index) { + if (index < 0 || index >= m_uavGadgetList->count()) + index = m_defaultIndex; + QString classId = m_uavGadgetList->itemData(index).toString(); if (m_uavGadget && (m_uavGadget->classId() == classId)) return;