Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add convenience methods for pushing a non-widget-based message to Qgs…
…MessageBar

- Switch some WARNING messages over to INFO
- Add default icon for CRITICAL messages
  • Loading branch information
dakcarto committed Jan 12, 2013
1 parent a369ed0 commit bc4f8f2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 30 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -189,6 +189,7 @@
<file>themes/default/mIconCollapse.png</file>
<file>themes/default/mIconConnect.png</file>
<file>themes/default/mIconClear.png</file>
<file>themes/default/mIconCritical.png</file>
<file>themes/default/mIconDbSchema.png</file>
<file>themes/default/mIconDelete.png</file>
<file>themes/default/mIconEditable.png</file>
Expand Down
Binary file added images/themes/default/mIconCritical.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions python/gui/qgsmessagebar.sip
Expand Up @@ -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 );
Expand Down
16 changes: 7 additions & 9 deletions src/app/qgisapp.cpp
Expand Up @@ -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)))
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}

Expand Down
23 changes: 10 additions & 13 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -15,7 +15,6 @@

#include "qgsmaptooledit.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmessagebar.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
Expand Down Expand Up @@ -124,20 +123,18 @@ int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& 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 );
}
12 changes: 5 additions & 7 deletions src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -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"
Expand All @@ -38,12 +37,11 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv
if ( !canvas->currentLayer()
|| ( vlayer = qobject_cast<QgsVectorLayer *>( 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;
}
Expand Down
26 changes: 25 additions & 1 deletion src/gui/qgsmessagebar.cpp
Expand Up @@ -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 );
}
Expand All @@ -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() )
Expand Down
5 changes: 5 additions & 0 deletions src/gui/qgsmessagebar.h
Expand Up @@ -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 );
Expand Down

0 comments on commit bc4f8f2

Please sign in to comment.