Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix #6957, move 'not vector/editable layer' dialogs to message bar fo…
…r map edit and select tools

- Move notifications to base QgsMapToolEdit class
- Add QgsMessageBar::INFO icon (also useful for lightweight WARNING)
  • Loading branch information
dakcarto committed Jan 12, 2013
1 parent d8c1593 commit 2c36e7d
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 39 deletions.
1 change: 1 addition & 0 deletions images/images.qrc
Expand Up @@ -197,6 +197,7 @@
<file>themes/default/mIconFavourites.png</file>
<file>themes/default/mIconFirst.png</file>
<file>themes/default/mIconGeometryLayer.png</file>
<file>themes/default/mIconInfo.png</file>
<file>themes/default/mIconLast.png</file>
<file>themes/default/mIconLayer.png</file>
<file>themes/default/mIconLineLayer.png</file>
Expand Down
Binary file added images/themes/default/mIconInfo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -4040,11 +4040,11 @@ void QgisApp::labeling()
if ( layer == NULL || layer->type() != QgsMapLayer::VectorLayer )
{
QWidget* msg = QgsMessageBar::createMessage(
tr( "Labeling: " ),
tr( "Labeling Options: " ),
tr( "Please select a vector layer first." ) ,
QgsApplication::getThemeIcon( "/mIconWarn.png" ),
QgsApplication::getThemeIcon( "/mIconInfo.png" ),
mInfoBar );
mInfoBar->pushWidget( msg, QgsMessageBar::WARNING, 4 );
mInfoBar->pushWidget( msg, QgsMessageBar::WARNING, 5 );
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/app/qgsmaptooladdfeature.cpp
Expand Up @@ -54,8 +54,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )

if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
notifyNotVectorLayer();
return;
}

Expand All @@ -72,9 +71,7 @@ void QgsMapToolAddFeature::canvasReleaseEvent( QMouseEvent * e )

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down
9 changes: 2 additions & 7 deletions src/app/qgsmaptooladdpart.cpp
Expand Up @@ -39,18 +39,13 @@ void QgsMapToolAddPart::canvasReleaseEvent( QMouseEvent * e )
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
QMessageBox::information( 0,
tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
notifyNotVectorLayer();
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0,
tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/app/qgsmaptooladdring.cpp
Expand Up @@ -39,16 +39,13 @@ void QgsMapToolAddRing::canvasReleaseEvent( QMouseEvent * e )

if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
notifyNotVectorLayer();
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down
21 changes: 21 additions & 0 deletions src/app/qgsmaptooledit.cpp
Expand Up @@ -14,6 +14,9 @@
***************************************************************************/

#include "qgsmaptooledit.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmessagebar.h"
#include "qgsproject.h"
#include "qgsmapcanvas.h"
#include "qgsrubberband.h"
Expand Down Expand Up @@ -119,4 +122,22 @@ int QgsMapToolEdit::addTopologicalPoints( const QList<QgsPoint>& geom )
return 0;
}

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

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 );
}
7 changes: 7 additions & 0 deletions src/app/qgsmaptooledit.h
Expand Up @@ -63,6 +63,13 @@ class QgsMapToolEdit: public QgsMapTool
@return 0 in case of success*/
int addTopologicalPoints( const QList<QgsPoint>& geom );

/**Display a timed message bar noting the active layer is not vector.
@note added in QGIS 1.9*/
void notifyNotVectorLayer();
/**Display a timed message bar noting the active vector layer is not editable.
@note added in QGIS 1.9*/
void notifyNotEditableLayer();

};

#endif
5 changes: 2 additions & 3 deletions src/app/qgsmaptoolmovefeature.cpp
Expand Up @@ -56,14 +56,13 @@ void QgsMapToolMoveFeature::canvasPressEvent( QMouseEvent * e )
QgsVectorLayer* vlayer = currentVectorLayer();
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down
8 changes: 7 additions & 1 deletion src/app/qgsmaptooloffsetcurve.cpp
Expand Up @@ -43,10 +43,16 @@ void QgsMapToolOffsetCurve::canvasPressEvent( QMouseEvent* e )
mGeometryModified = false;
mForceCopy = false;

if ( !mCanvas )
{
return;
}

//get selected features or snap to nearest feature if no selection
QgsVectorLayer* layer = currentVectorLayer();
if ( !mCanvas || !layer )
if ( !layer )
{
notifyNotVectorLayer();
return;
}

Expand Down
7 changes: 2 additions & 5 deletions src/app/qgsmaptoolreshape.cpp
Expand Up @@ -38,16 +38,13 @@ void QgsMapToolReshape::canvasReleaseEvent( QMouseEvent * e )

if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
notifyNotVectorLayer();
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down
9 changes: 8 additions & 1 deletion src/app/qgsmaptoolrotatepointsymbols.cpp
Expand Up @@ -78,10 +78,17 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
mActiveLayer = currentVectorLayer();
if ( !mActiveLayer )
{
notifyNotVectorLayer();
return;
}

if ( mActiveLayer->geometryType() != QGis::Point || !mActiveLayer->isEditable() )
if ( !mActiveLayer->isEditable() )
{
notifyNotEditableLayer();
return;
}

if ( mActiveLayer->geometryType() != QGis::Point )
{
return;
}
Expand Down
13 changes: 9 additions & 4 deletions src/app/qgsmaptoolselectutils.cpp
Expand Up @@ -16,6 +16,9 @@ email : jpalmer at linz dot govt dot nz
#include <limits>

#include "qgsmaptoolselectutils.h"
#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsmessagebar.h"
#include "qgsmapcanvas.h"
#include "qgsvectorlayer.h"
#include "qgsfeature.h"
Expand All @@ -35,10 +38,12 @@ QgsVectorLayer* QgsMapToolSelectUtils::getCurrentVectorLayer( QgsMapCanvas* canv
if ( !canvas->currentLayer()
|| ( vlayer = qobject_cast<QgsVectorLayer *>( canvas->currentLayer() ) ) == NULL )
{
QMessageBox::warning( canvas, QObject::tr( "No active vector layer" ),
QObject::tr( "To select features, you must choose a "
"vector layer by clicking on its name in the legend"
) );
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 );
}
return vlayer;
}
Expand Down
7 changes: 7 additions & 0 deletions src/app/qgsmaptoolsimplify.cpp
Expand Up @@ -251,6 +251,13 @@ bool QgsMapToolSimplify::calculateSliderBoudaries()
void QgsMapToolSimplify::canvasPressEvent( QMouseEvent * e )
{
QgsVectorLayer * vlayer = currentVectorLayer();

if ( !vlayer )
{
notifyNotVectorLayer();
return;
}

QgsPoint layerCoords = mCanvas->getCoordinateTransform()->toMapPoint( e->pos().x(), e->pos().y() );

double r = QgsTolerance::vertexSearchRadius( vlayer, mCanvas->mapRenderer() );
Expand Down
7 changes: 2 additions & 5 deletions src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -38,16 +38,13 @@ void QgsMapToolSplitFeatures::canvasReleaseEvent( QMouseEvent * e )

if ( !vlayer )
{
QMessageBox::information( 0, tr( "Not a vector layer" ),
tr( "The current layer is not a vector layer" ) );
notifyNotVectorLayer();
return;
}

if ( !vlayer->isEditable() )
{
QMessageBox::information( 0, tr( "Layer not editable" ),
tr( "Cannot edit the vector layer. Use 'Toggle Editing' to make it editable." )
);
notifyNotEditableLayer();
return;
}

Expand Down

0 comments on commit 2c36e7d

Please sign in to comment.