diff --git a/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp b/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp index 60ca801ee..60323135b 100644 --- a/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetdecorator.cpp @@ -40,6 +40,7 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QListsetParent(this); m_toolbar->setMinimumContentsLength(15); foreach (IUAVGadgetConfiguration *config, *m_configurations) m_toolbar->addItem(config->name()); @@ -49,6 +50,12 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QListat(index); loadConfiguration(config); diff --git a/ground/src/plugins/coreplugin/uavgadgetdecorator.h b/ground/src/plugins/coreplugin/uavgadgetdecorator.h index 04a1078d0..a99ac1cbf 100644 --- a/ground/src/plugins/coreplugin/uavgadgetdecorator.h +++ b/ground/src/plugins/coreplugin/uavgadgetdecorator.h @@ -38,6 +38,7 @@ class UAVGadgetDecorator : public IUAVGadget Q_OBJECT public: explicit UAVGadgetDecorator(IUAVGadget *gadget, QList *configurations); + ~UAVGadgetDecorator(); QWidget *widget() { return m_gadget->widget(); } QComboBox *toolBar() { return m_toolbar; } diff --git a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp index 1ac03da7a..fcb93cf10 100644 --- a/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetinstancemanager.cpp @@ -63,6 +63,7 @@ UAVGadgetInstanceManager::~UAVGadgetInstanceManager() { foreach (IOptionsPage *page, m_optionsPages) { m_pm->removeObject(page); + delete page; } } @@ -143,7 +144,7 @@ IUAVGadget *UAVGadgetInstanceManager::createGadget(QString classId, QWidget *par IUAVGadgetFactory *f = factory(classId); if (f) { QList *configs = configurations(classId); - IUAVGadget *g = f->createGadget(0); + IUAVGadget *g = f->createGadget(parent); IUAVGadget *gadget = new UAVGadgetDecorator(g, configs); m_gadgetInstances.append(gadget); connect(this, SIGNAL(configurationAdded(IUAVGadgetConfiguration*)), gadget, SLOT(configurationAdded(IUAVGadgetConfiguration*))); @@ -159,6 +160,8 @@ void UAVGadgetInstanceManager::removeGadget(IUAVGadget *gadget) { if (m_gadgetInstances.contains(gadget)) { m_gadgetInstances.removeOne(gadget); + delete gadget; + gadget = 0; } } diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp index a82b8b157..4f9f2c6f2 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetmanager.cpp @@ -167,7 +167,8 @@ UAVGadgetManagerPrivate::~UAVGadgetManagerPrivate() UAVGadgetManager::UAVGadgetManager(ICore *core, QWidget *parent) : QWidget(parent), m_showToolbars(false), - m_d(new UAVGadgetManagerPrivate(core, parent)) + m_d(new UAVGadgetManagerPrivate(core, parent)), + m_uavGadgetMode(0) { connect(m_d->m_core, SIGNAL(contextAboutToChange(Core::IContext *)), @@ -368,11 +369,10 @@ void UAVGadgetManager::closeView(Core::Internal::UAVGadgetView *view) return; IUAVGadget *gadget = view->gadget(); + emptyView(view); UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); im->removeGadget(gadget); - emptyView(view); - SplitterOrView *splitter = m_d->m_splitterOrView->findSplitter(splitterOrView); Q_ASSERT(splitterOrView->hasGadget() == false); Q_ASSERT(splitter->isSplitter() == true); @@ -442,8 +442,9 @@ bool UAVGadgetManager::restoreState(const QByteArray &state) removeAllSplits(); UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); - im->removeGadget(m_d->m_splitterOrView->view()->gadget()); + IUAVGadget *gadget = m_d->m_splitterOrView->view()->gadget(); emptyView(m_d->m_splitterOrView->view()); + im->removeGadget(gadget); QDataStream stream(state); QByteArray version; @@ -544,15 +545,15 @@ void UAVGadgetManager::removeAllSplits() 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); setCurrentGadget(uavGadget); + UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); + foreach (IUAVGadget *g, gadgets) { + im->removeGadget(g); + } } void UAVGadgetManager::gotoOtherSplit() diff --git a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp index e23a6c0cd..a34f42dcc 100644 --- a/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetmanager/uavgadgetview.cpp @@ -67,10 +67,10 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge QWidget(parent), m_uavGadgetManager(uavGadgetManager), m_uavGadget(uavGadget), - m_toolBar(new QWidget), + m_toolBar(new QWidget(this)), m_defaultToolBar(new QComboBox(this)), - m_uavGadgetList(new QComboBox), - m_closeButton(new QToolButton), + m_uavGadgetList(new QComboBox(this)), + m_closeButton(new QToolButton(this)), m_defaultIndex(0), m_activeLabel(new QLabel) { @@ -97,14 +97,14 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge m_defaultToolBar->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); m_activeToolBar = m_defaultToolBar; - QHBoxLayout *toolBarLayout = new QHBoxLayout; + QHBoxLayout *toolBarLayout = new QHBoxLayout(m_toolBar); toolBarLayout->setMargin(0); toolBarLayout->setSpacing(0); toolBarLayout->addWidget(m_defaultToolBar); m_toolBar->setLayout(toolBarLayout); m_toolBar->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::MinimumExpanding); - QWidget *spacerWidget = new QWidget; + QWidget *spacerWidget = new QWidget(this); spacerWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); m_activeLabel->setTextFormat(Qt::RichText); @@ -113,7 +113,8 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge m_closeButton->setAutoRaise(true); m_closeButton->setIcon(QIcon(":/core/images/closebutton.png")); - QHBoxLayout *toplayout = new QHBoxLayout; + m_top = new Utils::StyledBar(this); + QHBoxLayout *toplayout = new QHBoxLayout(m_top); toplayout->setSpacing(0); toplayout->setMargin(0); toplayout->addWidget(m_uavGadgetList); @@ -122,7 +123,6 @@ UAVGadgetView::UAVGadgetView(Core::UAVGadgetManager *uavGadgetManager, IUAVGadge toplayout->addWidget(m_activeLabel); toplayout->addWidget(m_closeButton); - m_top = new Utils::StyledBar; m_top->setLayout(toplayout); tl->addWidget(m_top); @@ -162,6 +162,7 @@ void UAVGadgetView::removeGadget() return; tl->removeWidget(m_uavGadget->widget()); + m_uavGadget->setParent(0); m_uavGadget->widget()->setParent(0); QWidget *toolBar = m_uavGadget->toolBar(); if (toolBar != 0) { @@ -221,10 +222,11 @@ void UAVGadgetView::listSelectionActivated(int index) if (m_uavGadget && (m_uavGadget->classId() == classId)) return; UAVGadgetInstanceManager *im = ICore::instance()->uavGadgetInstanceManager(); - im->removeGadget(m_uavGadget); + IUAVGadget *gadgetToRemove = m_uavGadget; IUAVGadget *gadget = im->createGadget(classId, this); setGadget(gadget); m_uavGadgetManager->setCurrentGadget(gadget); + im->removeGadget(gadgetToRemove); } int UAVGadgetView::indexOfClassId(QString classId) @@ -241,7 +243,7 @@ SplitterOrView::SplitterOrView(Core::UAVGadgetManager *uavGadgetManager, Core::I m_uavGadgetManager(uavGadgetManager), m_isRoot(isRoot) { - m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget); + m_view = new UAVGadgetView(m_uavGadgetManager, uavGadget, this); m_layout = new QStackedLayout(this); m_splitter = 0; m_layout->addWidget(m_view); diff --git a/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp b/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp index db36108a0..e474789a6 100644 --- a/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp +++ b/ground/src/plugins/coreplugin/uavgadgetoptionspagedecorator.cpp @@ -41,6 +41,7 @@ UAVGadgetOptionsPageDecorator::UAVGadgetOptionsPageDecorator(IOptionsPage *page, m_id(config->name()), m_category(config->classId()) { + m_optionsPage->setParent(this); m_instanceManager = ICore::instance()->uavGadgetInstanceManager(); m_categoryTr = m_instanceManager->gadgetName(m_category); } diff --git a/ground/src/plugins/uavobjects/uavobjectmanager.cpp b/ground/src/plugins/uavobjects/uavobjectmanager.cpp index fde3eb031..92de988f6 100644 --- a/ground/src/plugins/uavobjects/uavobjectmanager.cpp +++ b/ground/src/plugins/uavobjects/uavobjectmanager.cpp @@ -35,6 +35,11 @@ UAVObjectManager::UAVObjectManager() mutex = new QMutex(QMutex::Recursive); } +UAVObjectManager::~UAVObjectManager() +{ + delete mutex; +} + /** * Register an object with the manager. This function must be called for all newly created instances. * A new instance can be created directly by instantiating a new object or by calling clone() of diff --git a/ground/src/plugins/uavobjects/uavobjectmanager.h b/ground/src/plugins/uavobjects/uavobjectmanager.h index 3c742b19f..e32a56964 100644 --- a/ground/src/plugins/uavobjects/uavobjectmanager.h +++ b/ground/src/plugins/uavobjects/uavobjectmanager.h @@ -42,6 +42,7 @@ class UAVOBJECTS_EXPORT UAVObjectManager: public QObject public: UAVObjectManager(); + ~UAVObjectManager(); bool registerObject(UAVDataObject* obj); QList< QList > getObjects();