Skip to content

Commit

Permalink
Show message in message bar if feture has no geometry / empty geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Jan 11, 2016
1 parent 1bc2c39 commit fb996ae
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python/gui/qgsmapcanvas.sip
Expand Up @@ -506,6 +506,9 @@ class QgsMapCanvas : QGraphicsView
//! @note added in 2.12
void layerStyleOverridesChanged();

//! emit a message (usually to be displayed in a message bar)
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );

protected:
//! Overridden standard event to be gestures aware
bool event( QEvent * e );
Expand Down
9 changes: 9 additions & 0 deletions src/app/qgisapp.cpp
Expand Up @@ -618,6 +618,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,

// "theMapCanvas" used to find this canonical instance later
mMapCanvas = new QgsMapCanvas( centralWidget, "theMapCanvas" );
connect( mMapCanvas, SIGNAL( messageEmitted( const QString&, const QString&, QgsMessageBar::MessageLevel ) ),
this, SLOT( displayMessage( const QString&, const QString&, QgsMessageBar::MessageLevel ) ) );
mMapCanvas->setWhatsThis( tr( "Map canvas. This is where raster and vector "
"layers are displayed when added to the map" ) );

Expand Down Expand Up @@ -1032,6 +1034,8 @@ QgisApp::QgisApp()
setupUi( this );
mInternalClipboard = new QgsClipboard;
mMapCanvas = new QgsMapCanvas();
connect( mMapCanvas, SIGNAL( messageEmitted( const QString&, const QString&, QgsMessageBar::MessageLevel ) ),
this, SLOT( displayMessage( const QString&, const QString&, QgsMessageBar::MessageLevel ) ) );
mMapCanvas->freeze();
mLayerTreeView = new QgsLayerTreeView( this );
mUndoWidget = new QgsUndoWidget( nullptr, mMapCanvas );
Expand Down Expand Up @@ -9366,6 +9370,11 @@ void QgisApp::displayMapToolMessage( const QString& message, QgsMessageBar::Mess
}
}

void QgisApp::displayMessage( const QString& title, const QString& message, QgsMessageBar::MessageLevel level )
{
messageBar()->pushMessage( title, message, level, messageTimeout() );
}

void QgisApp::removeMapToolMessage()
{
// remove previous message
Expand Down
1 change: 1 addition & 0 deletions src/app/qgisapp.h
Expand Up @@ -1084,6 +1084,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
void showRotation();
void showStatusMessage( const QString& theMessage );
void displayMapToolMessage( const QString& message, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO );
void displayMessage( const QString& title, const QString& message, QgsMessageBar::MessageLevel level );
void removeMapToolMessage();
void updateMouseCoordinatePrecision();
void hasCrsTransformEnabled( bool theFlag );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -356,7 +356,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
QgsVectorLayer* vl = mFilterModel->layer();
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
if ( canvas && vl && vl->geometryType() != QGis::NoGeometry )
{
{
menu->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToCurrentFeature() ) );
}

Expand Down
11 changes: 11 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -1084,8 +1084,19 @@ void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
}

QgsGeometry* geom = fet.geometry();

QString errorMessage;
if ( !geom || !geom->geometry() )
{
errorMessage = tr( "Feature does not have a geometry" );
}
else if ( geom->geometry()->isEmpty() )
{
errorMessage = tr( "Feature geometry is empty" );
}
if ( !errorMessage.isEmpty() )
{
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
return;
}

Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -22,6 +22,7 @@

#include "qgsexpressioncontext.h"
#include "qgsfeature.h"
#include "qgsmessagebar.h"
#include "qgsrectangle.h"
#include "qgspoint.h"
#include "qgis.h"
Expand Down Expand Up @@ -586,6 +587,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! @note added in 2.12
void layerStyleOverridesChanged();

//! emit a message (usually to be displayed in a message bar)
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );

protected:
#ifdef HAVE_TOUCH
//! Overridden standard event to be gestures aware
Expand Down

0 comments on commit fb996ae

Please sign in to comment.