QGIS API Documentation  2.99.0-Master (bdf46d7)
qgsmaptoolidentifyfeature.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptoolidentifyfeature.cpp
3  --------------------------------------
4  Date : 22.5.2014
5  Copyright : (C) 2014 Denis Rouzaud
6  Email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <QMouseEvent>
17 
18 #include "qgscursors.h"
20 #include "qgsmapcanvas.h"
21 
23  : QgsMapToolIdentify( canvas )
24  , mCanvas( canvas )
25  , mLayer( vl )
26 {
27  mToolName = tr( "Identify feature" );
28 
29  // set cursor
30  QPixmap cursorPixmap = QPixmap( ( const char ** ) cross_hair_cursor );
31  mCursor = QCursor( cursorPixmap, 1, 1 );
32 }
33 
35 {
36 
37  QgsPoint point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
38 
39  QList<IdentifyResult> results;
40  if ( !identifyVectorLayer( &results, mLayer, point ) )
41  return;
42 
43  // TODO: display a menu when several features identified
44 
45  emit featureIdentified( results[0].mFeature );
46  emit featureIdentified( results[0].mFeature.id() );
47 }
48 
50 {
51  if ( e->key() == Qt::Key_Escape )
52  {
53  mCanvas->unsetMapTool( this );
54  }
55 }
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QgsPoint toMapCoordinates(int x, int y) const
virtual void keyPressEvent(QKeyEvent *e) override
Key event for overriding. Default implementation does nothing.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:72
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:206
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:195
Map tool for identifying features in layers.
A class to represent a point.
Definition: qgspoint.h:37
QgsMapToolIdentifyFeature(QgsMapCanvas *canvas, QgsVectorLayer *vl=nullptr)
QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer.
virtual void canvasReleaseEvent(QgsMapMouseEvent *e) override
Mouse release event for overriding. Default implementation does nothing.
void featureIdentified(const QgsFeature &)
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
const char * cross_hair_cursor[]
Definition: qgscursors.cpp:143
Represents a vector layer which manages a vector based data sets.
bool identifyVectorLayer(QList< IdentifyResult > *results, QgsVectorLayer *layer, const QgsPoint &point)