Skip to content

Commit bc4f8f2

Browse files
committed
Add convenience methods for pushing a non-widget-based message to QgsMessageBar
- Switch some WARNING messages over to INFO - Add default icon for CRITICAL messages
1 parent a369ed0 commit bc4f8f2

File tree

8 files changed

+58
-30
lines changed

8 files changed

+58
-30
lines changed

images/images.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<file>themes/default/mIconCollapse.png</file>
190190
<file>themes/default/mIconConnect.png</file>
191191
<file>themes/default/mIconClear.png</file>
192+
<file>themes/default/mIconCritical.png</file>
192193
<file>themes/default/mIconDbSchema.png</file>
193194
<file>themes/default/mIconDelete.png</file>
194195
<file>themes/default/mIconEditable.png</file>
570 Bytes
Loading

python/gui/qgsmessagebar.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class QgsMessageBar: QFrame
3939
//! make out a widget containing icon, title and message to be displayed on the bar
4040
static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 ) /Factory/;
4141

42+
//! convenience method for pushing a non-widget-based message to the bar
43+
void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 );
44+
//! convenience method for pushing a non-widget-based message with title to the bar
45+
void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
46+
4247
signals:
4348
//! emitted when a message widget is added to the bar
4449
void widgetAdded( QWidget *widget );

src/app/qgisapp.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,8 +1891,8 @@ void QgisApp::createCanvasTools()
18911891
mMapTools.mAddFeature->setAction( mActionAddFeature );
18921892
mMapTools.mMoveFeature = new QgsMapToolMoveFeature( mMapCanvas );
18931893
mMapTools.mMoveFeature->setAction( mActionMoveFeature );
1894-
mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas);
1895-
mMapTools.mRotateFeature->setAction(mActionRotateFeature);
1894+
mMapTools.mRotateFeature = new QgsMapToolRotateFeature( mMapCanvas );
1895+
mMapTools.mRotateFeature->setAction( mActionRotateFeature );
18961896
//need at least geos 3.3 for OffsetCurve tool
18971897
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
18981898
((GEOS_VERSION_MAJOR>3) || ((GEOS_VERSION_MAJOR==3) && (GEOS_VERSION_MINOR>=3)))
@@ -3422,7 +3422,7 @@ bool QgisApp::addProject( QString projectFile )
34223422
{
34233423
// create the notification widget for macros
34243424

3425-
QWidget *macroMsg = QgsMessageBar::createMessage( tr( "Security warning:" ),
3425+
QWidget *macroMsg = QgsMessageBar::createMessage( tr( "Security warning" ),
34263426
tr( "project macros have been disabled." ),
34273427
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
34283428
mInfoBar );
@@ -4039,12 +4039,10 @@ void QgisApp::labeling()
40394039
QgsMapLayer* layer = activeLayer();
40404040
if ( layer == NULL || layer->type() != QgsMapLayer::VectorLayer )
40414041
{
4042-
QWidget* msg = QgsMessageBar::createMessage(
4043-
tr( "Labeling Options: " ),
4044-
tr( "Please select a vector layer first." ) ,
4045-
QgsApplication::getThemeIcon( "/mIconInfo.png" ),
4046-
mInfoBar );
4047-
mInfoBar->pushWidget( msg, QgsMessageBar::WARNING, 5 );
4042+
messageBar()->pushMessage( tr( "Labeling Options" ),
4043+
tr( "Please select a vector layer first" ),
4044+
QgsMessageBar::INFO,
4045+
5 );
40484046
return;
40494047
}
40504048

src/app/qgsmaptooledit.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "qgsmaptooledit.h"
1717
#include "qgisapp.h"
18-
#include "qgsapplication.h"
1918
#include "qgsmessagebar.h"
2019
#include "qgsproject.h"
2120
#include "qgsmapcanvas.h"
@@ -124,20 +123,18 @@ int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
124123

125124
void QgsMapToolEdit::notifyNotVectorLayer()
126125
{
127-
QWidget* msg = QgsMessageBar::createMessage(
128-
QObject::tr( "No active vector layer: " ),
129-
QObject::tr( "Choose a vector layer in the legend" ) ,
130-
QgsApplication::getThemeIcon( "/mIconInfo.png" ),
131-
QgisApp::instance()->messageBar() );
132-
QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 );
126+
QgisApp::instance()->messageBar()->pushMessage(
127+
tr( "No active vector layer" ),
128+
tr( "Choose a vector layer in the legend" ),
129+
QgsMessageBar::INFO,
130+
5 );
133131
}
134132

135133
void QgsMapToolEdit::notifyNotEditableLayer()
136134
{
137-
QWidget* msg = QgsMessageBar::createMessage(
138-
QObject::tr( "Layer not editable: " ),
139-
QObject::tr( "Use 'Toggle Editing' to make it editable" ) ,
140-
QgsApplication::getThemeIcon( "/mIconInfo.png" ),
141-
QgisApp::instance()->messageBar() );
142-
QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 );
135+
QgisApp::instance()->messageBar()->pushMessage(
136+
tr( "Layer not editable" ),
137+
tr( "Use 'Toggle Editing' to make it editable" ),
138+
QgsMessageBar::INFO,
139+
5 );
143140
}

src/app/qgsmaptoolselectutils.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ email : jpalmer at linz dot govt dot nz
1717

1818
#include "qgsmaptoolselectutils.h"
1919
#include "qgisapp.h"
20-
#include "qgsapplication.h"
2120
#include "qgsmessagebar.h"
2221
#include "qgsmapcanvas.h"
2322
#include "qgsvectorlayer.h"
@@ -38,12 +37,11 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv
3837
if ( !canvas->currentLayer()
3938
|| ( vlayer = qobject_cast<QgsVectorLayer *>( canvas->currentLayer() ) ) == NULL )
4039
{
41-
QWidget* msg = QgsMessageBar::createMessage(
42-
QObject::tr( "No active vector layer: " ),
43-
QObject::tr( "To select features, choose a vector layer in the legend" ) ,
44-
QgsApplication::getThemeIcon( "/mIconInfo.png" ),
45-
QgisApp::instance()->messageBar() );
46-
QgisApp::instance()->messageBar()->pushWidget( msg, QgsMessageBar::WARNING, 5 );
40+
QgisApp::instance()->messageBar()->pushMessage(
41+
QObject::tr( "No active vector layer" ),
42+
QObject::tr( "To select features, choose a vector layer in the legend" ),
43+
QgsMessageBar::INFO,
44+
5 );
4745
}
4846
return vlayer;
4947
}

src/gui/qgsmessagebar.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,12 @@ QWidget* QgsMessageBar::createMessage( const QString &title, const QString &text
280280

281281
if ( !title.isEmpty() )
282282
{
283-
QLabel *lblTitle = new QLabel( title, widget );
283+
// add ':' to end of title
284+
QString t = title.trimmed();
285+
if ( !t.endsWith( ":" ) )
286+
t += ":";
287+
288+
QLabel *lblTitle = new QLabel( t, widget );
284289
lblTitle->setObjectName( "mMsgTitle" );
285290
layout->addWidget( lblTitle );
286291
}
@@ -294,6 +299,25 @@ QWidget* QgsMessageBar::createMessage( const QString &title, const QString &text
294299
return widget;
295300
}
296301

302+
void QgsMessageBar::pushMessage( const QString &title, const QString &text, MessageLevel level, int duration )
303+
{
304+
QString msgIcon( "/mIconInfo.png" );
305+
switch ( level )
306+
{
307+
case QgsMessageBar::CRITICAL:
308+
msgIcon = QString( "/mIconCritical.png" );
309+
break;
310+
case QgsMessageBar::WARNING:
311+
msgIcon = QString( "/mIconWarn.png" );
312+
break;
313+
default:
314+
break;
315+
}
316+
317+
QWidget *msg = QgsMessageBar::createMessage( title, text, QgsApplication::getThemeIcon( msgIcon ), this );
318+
pushWidget( msg, level, duration );
319+
}
320+
297321
void QgsMessageBar::updateCountdown()
298322
{
299323
if ( !mCountdownTimer->isActive() )

src/gui/qgsmessagebar.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ class GUI_EXPORT QgsMessageBar: public QFrame
7777
//! make out a widget containing icon, title and message to be displayed on the bar
7878
static QWidget* createMessage( const QString &title, const QString &text, const QIcon &icon, QWidget *parent = 0 );
7979

80+
//! convenience method for pushing a non-widget-based message to the bar
81+
void pushMessage( const QString &text, MessageLevel level = INFO, int duration = 0 ) { pushMessage( QString::null, text, level, duration ); }
82+
//! convenience method for pushing a non-widget-based message with title to the bar
83+
void pushMessage( const QString &title, const QString &text, MessageLevel level = INFO, int duration = 0 );
84+
8085
signals:
8186
//! emitted when a message widget is added to the bar
8287
void widgetAdded( QWidget *widget );

0 commit comments

Comments
 (0)