Skip to content
Permalink
Browse files

Always log message bar messages to message log

Mainly so they don't just disappear on the user
  • Loading branch information
NathanW2 committed Jul 24, 2017
1 parent 12c634c commit 391712d2d42a761acb4bacce81cbe9ed8da52f6b
Showing with 102 additions and 0 deletions.
  1. +30 −0 python/gui/qgsmessagebaritem.sip
  2. +22 −0 src/gui/qgsmessagebar.cpp
  3. +25 −0 src/gui/qgsmessagebaritem.cpp
  4. +25 −0 src/gui/qgsmessagebaritem.h
@@ -41,26 +41,56 @@ make out a widget containing a widget to be displayed on the bar
:rtype: QgsMessageBarItem
%End

QString text() const;
%Docstring
Returns the text for the message.
:rtype: str
%End

QgsMessageBarItem *setTitle( const QString &title );
%Docstring
:rtype: QgsMessageBarItem
%End

QString title() const;
%Docstring
Returns the title for the message.
:rtype: str
%End

QgsMessageBarItem *setLevel( QgsMessageBar::MessageLevel level );
%Docstring
:rtype: QgsMessageBarItem
%End

QgsMessageBar::MessageLevel level() const;
%Docstring
Returns the message level for the message.
:rtype: QgsMessageBar.MessageLevel
%End

QgsMessageBarItem *setWidget( QWidget *widget );
%Docstring
:rtype: QgsMessageBarItem
%End

QWidget *widget() const;
%Docstring
Returns the widget for the message.
:rtype: QWidget
%End

QgsMessageBarItem *setIcon( const QIcon &icon );
%Docstring
:rtype: QgsMessageBarItem
%End

QIcon icon() const;
%Docstring
Returns the icon for the message.
:rtype: QIcon
%End

QgsMessageBarItem *setDuration( int duration );
%Docstring
:rtype: QgsMessageBarItem
@@ -18,6 +18,7 @@
#include "qgsmessagebar.h"
#include "qgsmessagebaritem.h"
#include "qgsapplication.h"
#include "qgsmessagelog.h"

#include <QWidget>
#include <QPalette>
@@ -268,6 +269,27 @@ void QgsMessageBar::pushItem( QgsMessageBarItem *item )
// avoid duplicated widget
popWidget( item );
showItem( item );

// Log all messages that are sent to the message bar into the message log so the
// user can get them back easier.
QString formattedTitle = QString( "%1 : %2" ).arg( item->title() ).arg( item->text() );
QgsMessageLog::MessageLevel level;
switch ( item->level() )
{
case QgsMessageBar::INFO:
level = QgsMessageLog::INFO;
break;
case QgsMessageBar::WARNING:
level = QgsMessageLog::WARNING;
break;
case QgsMessageBar::CRITICAL:
level = QgsMessageLog::CRITICAL;
break;
default:
level = QgsMessageLog::NONE;
break;
}
QgsMessageLog::logMessage( formattedTitle, tr( "Messages" ), level );
}

QgsMessageBarItem *QgsMessageBar::pushWidget( QWidget *widget, QgsMessageBar::MessageLevel level, int duration )
@@ -196,13 +196,23 @@ QgsMessageBarItem *QgsMessageBarItem::setText( const QString &text )
return this;
}

QString QgsMessageBarItem::text() const
{
return mText;
}

QgsMessageBarItem *QgsMessageBarItem::setTitle( const QString &title )
{
mTitle = title;
writeContent();
return this;
}

QString QgsMessageBarItem::title() const
{
return mTitle;
}

QgsMessageBarItem *QgsMessageBarItem::setLevel( QgsMessageBar::MessageLevel level )
{
mLevel = level;
@@ -211,6 +221,11 @@ QgsMessageBarItem *QgsMessageBarItem::setLevel( QgsMessageBar::MessageLevel leve
return this;
}

QgsMessageBar::MessageLevel QgsMessageBarItem::level() const
{
return mLevel;
}

QgsMessageBarItem *QgsMessageBarItem::setWidget( QWidget *widget )
{
if ( mWidget )
@@ -227,12 +242,22 @@ QgsMessageBarItem *QgsMessageBarItem::setWidget( QWidget *widget )
return this;
}

QWidget *QgsMessageBarItem::widget() const
{
return mWidget;
}

QgsMessageBarItem *QgsMessageBarItem::setIcon( const QIcon &icon )
{
mUserIcon = icon;
return this;
}

QIcon QgsMessageBarItem::icon() const
{
return mUserIcon;
}


QgsMessageBarItem *QgsMessageBarItem::setDuration( int duration )
{
@@ -48,14 +48,39 @@ class GUI_EXPORT QgsMessageBarItem : public QWidget

QgsMessageBarItem *setText( const QString &text );

/**
* Returns the text for the message.
*/
QString text() const;

QgsMessageBarItem *setTitle( const QString &title );

/**
* Returns the title for the message.
*/
QString title() const;

QgsMessageBarItem *setLevel( QgsMessageBar::MessageLevel level );

/**
* Returns the message level for the message.
*/
QgsMessageBar::MessageLevel level() const;

QgsMessageBarItem *setWidget( QWidget *widget );

/**
* Returns the widget for the message.
*/
QWidget *widget() const;

QgsMessageBarItem *setIcon( const QIcon &icon );

/**
* Returns the icon for the message.
*/
QIcon icon() const;

QgsMessageBarItem *setDuration( int duration );

//! returns the duration in second of the message

0 comments on commit 391712d

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