Skip to content

Commit eeaa54c

Browse files
committedOct 31, 2018
Prevent flooding (and app freeze) of items added to the message bar
1 parent 29c2598 commit eeaa54c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
 

‎src/gui/qgsmessagebar.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ QgsMessageBarItem *QgsMessageBar::pushWidget( QWidget *widget, Qgis::MessageLeve
298298

299299
void QgsMessageBar::pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level, int duration )
300300
{
301+
// keep the number of items in the message bar to a maximum of 20, avoids flooding (and freezing) of the main window
302+
if ( mItems.count() > 20 )
303+
mItems.removeFirst();
304+
305+
// block duplicate items, avoids flooding (and freezing) of the main window
306+
for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
307+
{
308+
if ( level == ( *it )->level() && title == ( *it )->title() && text == ( *it )->text() )
309+
return;
310+
}
311+
301312
QgsMessageBarItem *item = new QgsMessageBarItem( title, text, level, duration );
302313
pushItem( item );
303314
}

0 commit comments

Comments
 (0)
Please sign in to comment.