Skip to content
Permalink
Browse files

Speed up message bar operations when many messages are shown

Avoid unnecessary calls to setStyleSheet, which is slow when many
message bar items exists

Refs #29698
  • Loading branch information
nyalldawson committed May 26, 2020
1 parent fbcf39e commit 5dd29f065e57fde532a21ae1bc9311aef9378455
@@ -96,6 +96,7 @@ has no effect.
%End

signals:

void styleChanged( const QString &styleSheet );
%Docstring
emitted when the message level has changed
@@ -260,7 +260,13 @@ void QgsMessageBar::showItem( QgsMessageBarItem *item )
}

connect( mCurrentItem, &QgsMessageBarItem::styleChanged, this, &QWidget::setStyleSheet );
setStyleSheet( item->getStyleSheet() );

if ( item->level() != mPrevLevel )
{
setStyleSheet( item->getStyleSheet() );
mPrevLevel = item->level();
}

show();

emit widgetAdded( item );
@@ -164,6 +164,7 @@ class GUI_EXPORT QgsMessageBar: public QFrame
QTimer *mCountdownTimer = nullptr;
QProgressBar *mCountProgress = nullptr;
QString mCountStyleSheet;
Qgis::MessageLevel mPrevLevel = Qgis::MessageLevel::None;

private slots:
//! updates count of items in widget list
@@ -220,9 +220,13 @@ QString QgsMessageBarItem::title() const

QgsMessageBarItem *QgsMessageBarItem::setLevel( Qgis::MessageLevel level )
{
mLevel = level;
writeContent();
emit styleChanged( mStyleSheet );
if ( level != mLevel )
{
mLevel = level;
writeContent();
emit styleChanged( mStyleSheet );
}

return this;
}

@@ -104,7 +104,10 @@ class GUI_EXPORT QgsMessageBarItem : public QWidget
void dismiss();

signals:
//! emitted when the message level has changed

/**
* emitted when the message level has changed
*/
void styleChanged( const QString &styleSheet );

private slots:

0 comments on commit 5dd29f0

Please sign in to comment.
You can’t perform that action at this time.