Commit e8090947 authored by Mario Hlawitschka's avatar Mario Hlawitschka
Browse files

[FIX #107] fixed a memory leak where widgets have not been deleted properly

parent fb3b7787
...@@ -668,8 +668,7 @@ void WQtControlPanel::selectTreeItem() ...@@ -668,8 +668,7 @@ void WQtControlPanel::selectTreeItem()
if( m_moduleTreeWidget->selectedItems().size() != 0 ) if( m_moduleTreeWidget->selectedItems().size() != 0 )
{ {
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak clearAndDeleteTabs();
m_tabWidget->clear();
// disable delete action for tree items that have children. // disable delete action for tree items that have children.
if( m_moduleTreeWidget->selectedItems().at( 0 )->childCount() != 0 ) if( m_moduleTreeWidget->selectedItems().at( 0 )->childCount() != 0 )
...@@ -755,8 +754,7 @@ void WQtControlPanel::selectTreeItem() ...@@ -755,8 +754,7 @@ void WQtControlPanel::selectTreeItem()
void WQtControlPanel::selectRoiTreeItem() void WQtControlPanel::selectRoiTreeItem()
{ {
// TODO(schurade): qt doc says clear() doesn't delete tabs so this is possibly a memory leak clearAndDeleteTabs();
m_tabWidget->clear();
// Make compatibles toolbar empty // Make compatibles toolbar empty
{ {
...@@ -833,13 +831,13 @@ void WQtControlPanel::selectDataModule( boost::shared_ptr< WDataSet > dataSet ) ...@@ -833,13 +831,13 @@ void WQtControlPanel::selectDataModule( boost::shared_ptr< WDataSet > dataSet )
void WQtControlPanel::selectDataModule( osg::ref_ptr< WGETexture3D > texture ) void WQtControlPanel::selectDataModule( osg::ref_ptr< WGETexture3D > texture )
{ {
m_tabWidget->clear(); clearAndDeleteTabs();
buildPropTab( texture->getProperties(), texture->getInformationProperties() ); buildPropTab( texture->getProperties(), texture->getInformationProperties() );
} }
void WQtControlPanel::setNewActiveModule( boost::shared_ptr< WModule > module ) void WQtControlPanel::setNewActiveModule( boost::shared_ptr< WModule > module )
{ {
m_tabWidget->clear(); clearAndDeleteTabs();
// NOTE: this handles null pointers properly. // NOTE: this handles null pointers properly.
createCompatibleButtons( module ); createCompatibleButtons( module );
...@@ -1201,3 +1199,16 @@ QAction* WQtControlPanel::getMissingModuleAction() const ...@@ -1201,3 +1199,16 @@ QAction* WQtControlPanel::getMissingModuleAction() const
{ {
return m_missingModuleAction; return m_missingModuleAction;
} }
void WQtControlPanel::clearAndDeleteTabs()
{
m_tabWidget->setDisabled( true );
QWidget *widget;
while (( widget = m_tabWidget->widget( 0 ) ))
{
m_tabWidget->removeTab( 0 );
delete widget;
}
m_tabWidget->setEnabled( true );
}
...@@ -264,6 +264,12 @@ protected: ...@@ -264,6 +264,12 @@ protected:
*/ */
std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module ); std::list< WQtTreeItem* > findItemsByModule( boost::shared_ptr< WModule > module );
/**
* As QTabWidget::clear() does not delete tabs, we have to manage that ourselves.
* So this function clears all tabs and deletes the data as well.
*/
void clearAndDeleteTabs();
private: private:
WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget WQtTreeWidget* m_moduleTreeWidget; //!< pointer to the tree widget
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment