Skip to content
Permalink
Browse files
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 bc4f8f2ba2b8fc20399975a5387e83777ccf4295
@@ -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>
Binary file not shown.
@@ -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 );
@@ -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;
}

@@ -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<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 );
}
@@ -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<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;
}
@@ -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() )
@@ -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 );

0 comments on commit bc4f8f2

Please sign in to comment.