Skip to content

Commit

Permalink
Prevent flooding (and app freeze) of items added to the message bar
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Oct 31, 2018
1 parent f5a1b4e commit 4d33422
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/gui/qgsmessagebar.cpp
Expand Up @@ -298,6 +298,17 @@ QgsMessageBarItem *QgsMessageBar::pushWidget( QWidget *widget, Qgis::MessageLeve

void QgsMessageBar::pushMessage( const QString &title, const QString &text, Qgis::MessageLevel level, int duration )
{
// keep the number of items in the message bar to a maximum of 20, avoids flooding (and freezing) of the main window
if ( mItems.count() > 20 )
mItems.removeFirst();

// block duplicate items, avoids flooding (and freezing) of the main window
for ( auto it = mItems.constBegin(); it != mItems.constEnd(); ++it )
{
if ( level == ( *it )->level() && title == ( *it )->title() && text == ( *it )->text() )
return;
}

QgsMessageBarItem *item = new QgsMessageBarItem( title, text, level, duration );
pushItem( item );
}
Expand Down

0 comments on commit 4d33422

Please sign in to comment.