Skip to content

Commit

Permalink
Merge pull request #350 from matthias-kuhn/qgsmessagebar
Browse files Browse the repository at this point in the history
Transfer ownership of widgets to C++ when pushed to the QgsMessageBar
  • Loading branch information
wonder-sk committed Dec 28, 2012
2 parents 837f187 + 2b2da5d commit 5df8f2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/gui/qgsmessagebar.sip
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class QgsMessageBar: QFrame
* @param widget widget to add
* @param level is 0 for information, 1 for warning, 2 for critical
*/
void pushWidget( QWidget *widget, int level = 0 );
void pushWidget( QWidget *widget /Transfer/, int level = 0 );

/*! remove the passed widget from the bar (if previously added),
* then display the next one in the stack if any or hide the bar
Expand Down
10 changes: 9 additions & 1 deletion src/gui/qgsmessagebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ void QgsMessageBar::popItem( QgsMessageBarItem *item )
{
mLayout->removeWidget( mCurrentItem->widget() );
mCurrentItem->widget()->hide();
if ( mCurrentItem->widget()->parent() == this )
{
delete mCurrentItem->widget();
}
delete mCurrentItem;
mCurrentItem = 0;
}

Expand Down Expand Up @@ -126,6 +131,10 @@ bool QgsMessageBar::popWidget( QWidget *widget )
if ( item->widget() == widget )
{
mList.removeOne( item );
if ( item->widget()->parent() == this )
{
delete item->widget();
}
delete item;
return true;
}
Expand All @@ -141,7 +150,6 @@ bool QgsMessageBar::popWidget()

QgsMessageBarItem *item = mCurrentItem;
popItem( item );
delete item;

return true;
}
Expand Down

0 comments on commit 5df8f2c

Please sign in to comment.