Skip to content

Commit fb996ae

Browse files
committed
Show message in message bar if feture has no geometry / empty geometry
1 parent 1bc2c39 commit fb996ae

File tree

6 files changed

+29
-1
lines changed

6 files changed

+29
-1
lines changed

python/gui/qgsmapcanvas.sip

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,9 @@ class QgsMapCanvas : QGraphicsView
506506
//! @note added in 2.12
507507
void layerStyleOverridesChanged();
508508

509+
//! emit a message (usually to be displayed in a message bar)
510+
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
511+
509512
protected:
510513
//! Overridden standard event to be gestures aware
511514
bool event( QEvent * e );

src/app/qgisapp.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
618618

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

@@ -1032,6 +1034,8 @@ QgisApp::QgisApp()
10321034
setupUi( this );
10331035
mInternalClipboard = new QgsClipboard;
10341036
mMapCanvas = new QgsMapCanvas();
1037+
connect( mMapCanvas, SIGNAL( messageEmitted( const QString&, const QString&, QgsMessageBar::MessageLevel ) ),
1038+
this, SLOT( displayMessage( const QString&, const QString&, QgsMessageBar::MessageLevel ) ) );
10351039
mMapCanvas->freeze();
10361040
mLayerTreeView = new QgsLayerTreeView( this );
10371041
mUndoWidget = new QgsUndoWidget( nullptr, mMapCanvas );
@@ -9366,6 +9370,11 @@ void QgisApp::displayMapToolMessage( const QString& message, QgsMessageBar::Mess
93669370
}
93679371
}
93689372

9373+
void QgisApp::displayMessage( const QString& title, const QString& message, QgsMessageBar::MessageLevel level )
9374+
{
9375+
messageBar()->pushMessage( title, message, level, messageTimeout() );
9376+
}
9377+
93699378
void QgisApp::removeMapToolMessage()
93709379
{
93719380
// remove previous message

src/app/qgisapp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
10841084
void showRotation();
10851085
void showStatusMessage( const QString& theMessage );
10861086
void displayMapToolMessage( const QString& message, QgsMessageBar::MessageLevel level = QgsMessageBar::INFO );
1087+
void displayMessage( const QString& title, const QString& message, QgsMessageBar::MessageLevel level );
10871088
void removeMapToolMessage();
10881089
void updateMouseCoordinatePrecision();
10891090
void hasCrsTransformEnabled( bool theFlag );

src/gui/attributetable/qgsdualview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ void QgsDualView::viewWillShowContextMenu( QMenu* menu, const QModelIndex& atInd
356356
QgsVectorLayer* vl = mFilterModel->layer();
357357
QgsMapCanvas* canvas = mFilterModel->mapCanvas();
358358
if ( canvas && vl && vl->geometryType() != QGis::NoGeometry )
359-
{
359+
{
360360
menu->addAction( tr( "Zoom to feature" ), this, SLOT( zoomToCurrentFeature() ) );
361361
}
362362

src/gui/qgsmapcanvas.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,19 @@ void QgsMapCanvas::zoomToFeatureId( QgsVectorLayer* layer, QgsFeatureId id )
10841084
}
10851085

10861086
QgsGeometry* geom = fet.geometry();
1087+
1088+
QString errorMessage;
10871089
if ( !geom || !geom->geometry() )
10881090
{
1091+
errorMessage = tr( "Feature does not have a geometry" );
1092+
}
1093+
else if ( geom->geometry()->isEmpty() )
1094+
{
1095+
errorMessage = tr( "Feature geometry is empty" );
1096+
}
1097+
if ( !errorMessage.isEmpty() )
1098+
{
1099+
emit messageEmitted( tr( "Zoom to feature id failed" ), errorMessage, QgsMessageBar::WARNING );
10891100
return;
10901101
}
10911102

src/gui/qgsmapcanvas.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "qgsexpressioncontext.h"
2424
#include "qgsfeature.h"
25+
#include "qgsmessagebar.h"
2526
#include "qgsrectangle.h"
2627
#include "qgspoint.h"
2728
#include "qgis.h"
@@ -586,6 +587,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
586587
//! @note added in 2.12
587588
void layerStyleOverridesChanged();
588589

590+
//! emit a message (usually to be displayed in a message bar)
591+
void messageEmitted( const QString& title, const QString& message, QgsMessageBar::MessageLevel = QgsMessageBar::INFO );
592+
589593
protected:
590594
#ifdef HAVE_TOUCH
591595
//! Overridden standard event to be gestures aware

0 commit comments

Comments
 (0)