1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

GCS/core: Reduce number of memory leaks.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@431 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
ephy 2010-04-06 09:26:20 +00:00 committed by ephy
parent 583506cdba
commit 3fa05861c6
8 changed files with 39 additions and 18 deletions

View File

@ -40,6 +40,7 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfi
m_activeConfiguration(0),
m_configurations(configurations)
{
m_gadget->setParent(this);
m_toolbar->setMinimumContentsLength(15);
foreach (IUAVGadgetConfiguration *config, *m_configurations)
m_toolbar->addItem(config->name());
@ -49,6 +50,12 @@ UAVGadgetDecorator::UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfi
updateToolbar();
}
UAVGadgetDecorator::~UAVGadgetDecorator()
{
delete m_configurations;
delete m_toolbar;
}
void UAVGadgetDecorator::loadConfiguration(int index) {
IUAVGadgetConfiguration* config = m_configurations->at(index);
loadConfiguration(config);

View File

@ -38,6 +38,7 @@ class UAVGadgetDecorator : public IUAVGadget
Q_OBJECT
public:
explicit UAVGadgetDecorator(IUAVGadget *gadget, QList<IUAVGadgetConfiguration*> *configurations);
~UAVGadgetDecorator();
QWidget *widget() { return m_gadget->widget(); }
QComboBox *toolBar() { return m_toolbar; }

View File

@ -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<IUAVGadgetConfiguration*> *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;
}
}

View File

@ -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<IUAVGadget*> 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()

View File

@ -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);

View File

@ -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);
}

View File

@ -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

View File

@ -42,6 +42,7 @@ class UAVOBJECTS_EXPORT UAVObjectManager: public QObject
public:
UAVObjectManager();
~UAVObjectManager();
bool registerObject(UAVDataObject* obj);
QList< QList<UAVObject*> > getObjects();