diff --git a/images/images.qrc b/images/images.qrc index ed5a42ca92c..814fb90feeb 100644 --- a/images/images.qrc +++ b/images/images.qrc @@ -189,6 +189,7 @@ themes/default/mIconCollapse.png themes/default/mIconConnect.png themes/default/mIconClear.png + themes/default/mIconCritical.png themes/default/mIconDbSchema.png themes/default/mIconDelete.png themes/default/mIconEditable.png diff --git a/images/themes/default/mIconCritical.png b/images/themes/default/mIconCritical.png new file mode 100644 index 00000000000..73bcadbca85 Binary files /dev/null and b/images/themes/default/mIconCritical.png differ diff --git a/python/gui/qgsmessagebar.sip b/python/gui/qgsmessagebar.sip index dfbac8085b5..d871d07b45d 100644 --- a/python/gui/qgsmessagebar.sip +++ b/python/gui/qgsmessagebar.sip @@ -39,6 +39,11 @@ class QgsMessageBar: QFrame //! make out a widget containing icon, title and message to be displayed on the bar static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 ) /Factory/; + //! convenience method for pushing a non-widget-based message to the bar + void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 ); + //! convenience method for pushing a non-widget-based message with title to the bar + void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 ); + signals: //! emitted when a message widget is added to the bar void widgetAdded( QWidget *widget ); diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index ec3f00dadf4..b022aa3434e 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -1891,8 +1891,8 @@ void QgisApp::createCanvasTools() mMapTools.mAddFeature->setAction( mActionAddFeature ); mMapTools.mMoveFeature = new QgsMapToolMoveFeature( mMapCanvas ); mMapTools.mMoveFeature->setAction( mActionMoveFeature ); - mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas); - mMapTools.mRotateFeature->setAction(mActionRotateFeature); + mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas ); + mMapTools.mRotateFeature->setAction( mActionRotateFeature ); //need at least geos 3.3 for OffsetCurve tool #if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \ ((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3))) @@ -3422,7 +3422,7 @@ bool QgisApp::addProject( QString projectFile ) { // create the notification widget for macros - QWidget *macroMsg = QgsMessageBar::createMessage( tr( "Security warning:" ), + QWidget *macroMsg = QgsMessageBar::createMessage( tr( "Security warning" ), tr( "project macros have been disabled." ), QgsApplication::getThemeIcon( "/mIconWarn.png" ), mInfoBar ); @@ -4039,12 +4039,10 @@ void QgisApp::labeling() QgsMapLayer* layer = activeLayer(); if ( layer == NULL || layer->type() != QgsMapLayer::VectorLayer ) { - QWidget* msg = QgsMessageBar::createMessage( - tr( "Labeling Options: " ), - tr( "Please select a vector layer first." ) , - QgsApplication::getThemeIcon( "/mIconInfo.png" ), - mInfoBar ); - mInfoBar->pushWidget( msg, QgsMessageBar::WARNING, 5 ); + messageBar()->pushMessage( tr( "Labeling Options" ), + tr( "Please select a vector layer first" ), + QgsMessageBar::INFO, + 5 ); return; } diff --git a/src/app/qgsmaptooledit.cpp b/src/app/qgsmaptooledit.cpp index c90d24eba35..fda075ca6bb 100644 --- a/src/app/qgsmaptooledit.cpp +++ b/src/app/qgsmaptooledit.cpp @@ -15,7 +15,6 @@ #include "qgsmaptooledit.h" #include "qgisapp.h" -#include "qgsapplication.h" #include "qgsmessagebar.h" #include "qgsproject.h" #include "qgsmapcanvas.h" @@ -124,20 +123,18 @@ int QgsMapToolEdit::addTopologicalPoints( const QList& geom ) void QgsMapToolEdit::notifyNotVectorLayer() { - QWidget* msg = QgsMessageBar::createMessage( - QObject::tr( "No active vector layer: " ), - QObject::tr( "Choose a vector layer in the legend" ) , - QgsApplication::getThemeIcon( "/mIconInfo.png" ), - QgisApp::instance()->messageBar() ); - QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 ); + QgisApp::instance()->messageBar()->pushMessage( + tr( "No active vector layer" ), + tr( "Choose a vector layer in the legend" ), + QgsMessageBar::INFO, + 5 ); } void QgsMapToolEdit::notifyNotEditableLayer() { - QWidget* msg = QgsMessageBar::createMessage( - QObject::tr( "Layer not editable: " ), - QObject::tr( "Use 'Toggle Editing' to make it editable" ) , - QgsApplication::getThemeIcon( "/mIconInfo.png" ), - QgisApp::instance()->messageBar() ); - QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 ); + QgisApp::instance()->messageBar()->pushMessage( + tr( "Layer not editable" ), + tr( "Use 'Toggle Editing' to make it editable" ), + QgsMessageBar::INFO, + 5 ); } diff --git a/src/app/qgsmaptoolselectutils.cpp b/src/app/qgsmaptoolselectutils.cpp index 0e501daf19a..1bd162dbeb4 100644 --- a/src/app/qgsmaptoolselectutils.cpp +++ b/src/app/qgsmaptoolselectutils.cpp @@ -17,7 +17,6 @@ email : jpalmer at linz dot govt dot nz #include "qgsmaptoolselectutils.h" #include "qgisapp.h" -#include "qgsapplication.h" #include "qgsmessagebar.h" #include "qgsmapcanvas.h" #include "qgsvectorlayer.h" @@ -38,12 +37,11 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv if ( !canvas->currentLayer() || ( vlayer = qobject_cast( canvas->currentLayer() ) ) == NULL ) { - QWidget* msg = QgsMessageBar::createMessage( - QObject::tr( "No active vector layer: " ), - QObject::tr( "To select features, choose a vector layer in the legend" ) , - QgsApplication::getThemeIcon( "/mIconInfo.png" ), - QgisApp::instance()->messageBar() ); - QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 ); + QgisApp::instance()->messageBar()->pushMessage( + QObject::tr( "No active vector layer" ), + QObject::tr( "To select features, choose a vector layer in the legend" ), + QgsMessageBar::INFO, + 5 ); } return vlayer; } diff --git a/src/gui/qgsmessagebar.cpp b/src/gui/qgsmessagebar.cpp index d8695ddf8eb..65b82c80ec2 100644 --- a/src/gui/qgsmessagebar.cpp +++ b/src/gui/qgsmessagebar.cpp @@ -280,7 +280,12 @@ QWidget* QgsMessageBar::createMessage( const QString &title, const QString &text if ( !title.isEmpty() ) { - QLabel *lblTitle = new QLabel( title, widget ); + // add ':' to end of title + QString t = title.trimmed(); + if ( !t.endsWith( ":" ) ) + t += ":"; + + QLabel *lblTitle = new QLabel( t, widget ); lblTitle->setObjectName( "mMsgTitle" ); layout->addWidget( lblTitle ); } @@ -294,6 +299,25 @@ QWidget* QgsMessageBar::createMessage( const QString &title, const QString &text return widget; } +void QgsMessageBar::pushMessage( const QString &title, const QString &text, MessageLevel level, int duration ) +{ + QString msgIcon( "/mIconInfo.png" ); + switch ( level ) + { + case QgsMessageBar::CRITICAL: + msgIcon = QString( "/mIconCritical.png" ); + break; + case QgsMessageBar::WARNING: + msgIcon = QString( "/mIconWarn.png" ); + break; + default: + break; + } + + QWidget *msg = QgsMessageBar::createMessage( title, text, QgsApplication::getThemeIcon( msgIcon ), this ); + pushWidget( msg, level, duration ); +} + void QgsMessageBar::updateCountdown() { if ( !mCountdownTimer->isActive() ) diff --git a/src/gui/qgsmessagebar.h b/src/gui/qgsmessagebar.h index 2623fc35285..5538892edd8 100644 --- a/src/gui/qgsmessagebar.h +++ b/src/gui/qgsmessagebar.h @@ -77,6 +77,11 @@ class GUI_EXPORT QgsMessageBar: public QFrame //! make out a widget containing icon, title and message to be displayed on the bar static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 ); + //! convenience method for pushing a non-widget-based message to the bar + void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 ) { pushMessage( QString::null, text, level, duration ); } + //! convenience method for pushing a non-widget-based message with title to the bar + void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 ); + signals: //! emitted when a message widget is added to the bar void widgetAdded( QWidget *widget );