From a0628bf6daafb7a86e7cac0a6d87ed821240d7f2 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Fri, 11 Jan 2013 18:03:32 -0700 Subject: [PATCH] Add descriptive names to message bar levels (from Matthais Kuhn) - Enum containing INFO, WARNING and CRITICAL --- python/gui/qgsmessagebar.sip | 11 +++++++++-- src/app/qgisapp.cpp | 6 +++--- src/gui/qgsmessagebar.cpp | 8 ++++---- src/gui/qgsmessagebar.h | 11 +++++++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/python/gui/qgsmessagebar.sip b/python/gui/qgsmessagebar.sip index 3d8ce1554429..dfbac8085b5f 100644 --- a/python/gui/qgsmessagebar.sip +++ b/python/gui/qgsmessagebar.sip @@ -5,16 +5,23 @@ class QgsMessageBar: QFrame %End public: + enum MessageLevel + { + INFO = 0, + WARNING = 1, + CRITICAL = 2 + }; + QgsMessageBar( QWidget *parent = 0 ); ~QgsMessageBar(); /*! display a widget on the bar after hiding the currently visible one * and putting it in a stack * @param widget widget to add - * @param level is 0 for information, 1 for warning, 2 for critical + * @param level is QgsMessageBar::INFO, WARNING or CRITICAL * @param duration timeout duration of message in seconds, 0 value indicates no timeout */ - void pushWidget( QWidget *widget /Transfer/, int level = 0, int duration = 0 ); + void pushWidget( QWidget *widget /Transfer/, MessageLevel level = INFO, int duration = 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 diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index bd27fdb67610..0da5dd2ef67b 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -3427,7 +3427,7 @@ bool QgisApp::addProject( QString projectFile ) macroMsg->layout()->addWidget( btnEnableMacros ); // display the macros notification widget - mInfoBar->pushWidget( macroMsg, 1 ); + mInfoBar->pushWidget( macroMsg, QgsMessageBar::WARNING ); } } } @@ -4034,7 +4034,7 @@ void QgisApp::labeling() tr( "Please select a vector layer first." ) , QgsApplication::getThemeIcon( "/mIconWarn.png" ), mInfoBar ); - mInfoBar->pushWidget( msg, 1, 4 ); + mInfoBar->pushWidget( msg, QgsMessageBar::WARNING, 4 ); return; } @@ -5759,7 +5759,7 @@ void QgisApp::duplicateLayers( QList lyrList ) // display errors in message bar after duplication of layers foreach ( QWidget * msgBar, msgBars ) { - mInfoBar->pushWidget( msgBar, 1 ); + mInfoBar->pushWidget( msgBar, QgsMessageBar::WARNING ); } } diff --git a/src/gui/qgsmessagebar.cpp b/src/gui/qgsmessagebar.cpp index ed1216cf7345..d8695ddf8eb6 100644 --- a/src/gui/qgsmessagebar.cpp +++ b/src/gui/qgsmessagebar.cpp @@ -228,22 +228,22 @@ void QgsMessageBar::pushItem( QgsMessageBarItem *item ) emit widgetAdded( item->widget() ); } -void QgsMessageBar::pushWidget( QWidget *widget, int level, int duration ) +void QgsMessageBar::pushWidget( QWidget *widget, MessageLevel level, int duration ) { resetCountdown(); QString stylesheet; - if ( level >= 2 ) + if ( level >= CRITICAL ) { stylesheet = "QgsMessageBar { background-color: #d65253; border: 1px solid #9b3d3d; } " "QLabel { color: white; } "; } - else if ( level == 1 ) + else if ( level == WARNING ) { stylesheet = "QgsMessageBar { background-color: #ffc800; border: 1px solid #e0aa00; } " "QLabel { color: black; } "; } - else if ( level <= 0 ) + else if ( level <= INFO ) { stylesheet = "QgsMessageBar { background-color: #e7f5fe; border: 1px solid #b9cfe4; } " "QLabel { color: #2554a1; } "; diff --git a/src/gui/qgsmessagebar.h b/src/gui/qgsmessagebar.h index 91d898214147..2623fc352851 100644 --- a/src/gui/qgsmessagebar.h +++ b/src/gui/qgsmessagebar.h @@ -43,16 +43,23 @@ class GUI_EXPORT QgsMessageBar: public QFrame Q_OBJECT public: + enum MessageLevel + { + INFO = 0, + WARNING = 1, + CRITICAL = 2 + }; + QgsMessageBar( QWidget *parent = 0 ); ~QgsMessageBar(); /*! display a widget on the bar after hiding the currently visible one * and putting it in a stack * @param widget widget to add - * @param level is 0 for information, 1 for warning, 2 for critical + * @param level is QgsMessageBar::INFO, WARNING or CRITICAL * @param duration timeout duration of message in seconds, 0 value indicates no timeout */ - void pushWidget( QWidget *widget, int level = 0, int duration = 0 ); + void pushWidget( QWidget *widget, MessageLevel level = INFO, int duration = 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