Skip to content
Permalink
Browse files

Show message in message bar if feture has no geometry / empty geometry

  • Loading branch information
mhugent committed Jan 11, 2016
1 parent 1bc2c39 commit fb996ae7fab9e4a74151cee53aa03049f179116c
@@ -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 );
@@ -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" ) );

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

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

@@ -22,6 +22,7 @@

#include "qgsexpressioncontext.h"
#include "qgsfeature.h"
#include "qgsmessagebar.h"
#include "qgsrectangle.h"
#include "qgspoint.h"
#include "qgis.h"
@@ -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

0 comments on commit fb996ae

Please sign in to comment.
You can’t perform that action at this time.