QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
18 #include "qgsmapcanvas.h"
19 #include "qgsmapmouseevent.h"
20 
22  : QgsMapToolIdentify( canvas )
23  , mCanvas( canvas )
24  , mLayer( vl )
25 {
26  mToolName = tr( "Identify feature" );
27 
28  // set cursor
29  mCursor = QCursor( Qt::CrossCursor );
30 }
31 
33 {
34 
35  QgsPointXY point = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
36 
37  QList<IdentifyResult> results;
38  if ( !identifyVectorLayer( &results, mLayer, point ) )
39  return;
40 
41  // TODO: display a menu when several features identified
42 
43  emit featureIdentified( results[0].mFeature );
44  emit featureIdentified( results[0].mFeature.id() );
45 }
46 
48 {
49  if ( e->key() == Qt::Key_Escape )
50  {
51  mCanvas->unsetMapTool( this );
52  }
53 }
qgsmaptoolidentifyfeature.h
qgsmapcanvas.h
QgsMapToolIdentify
Map tool for identifying features in layers.
Definition: qgsmaptoolidentify.h:49
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.cpp:108
QgsMapToolIdentifyFeature::QgsMapToolIdentifyFeature
QgsMapToolIdentifyFeature(QgsMapCanvas *canvas, QgsVectorLayer *vl=nullptr)
QgsMapToolIdentifyFeature is a map tool to identify a feature on a chosen layer.
Definition: qgsmaptoolidentifyfeature.cpp:21
QgsMapToolIdentifyFeature::canvasReleaseEvent
void canvasReleaseEvent(QgsMapMouseEvent *e) override
Mouse release event for overriding. Default implementation does nothing.
Definition: qgsmaptoolidentifyfeature.cpp:32
QgsMapCanvas::getCoordinateTransform
const QgsMapToPixel * getCoordinateTransform()
Gets the current coordinate transform.
Definition: qgsmapcanvas.cpp:335
QgsMapToolIdentifyFeature::keyPressEvent
void keyPressEvent(QKeyEvent *e) override
Key event for overriding. Default implementation does nothing.
Definition: qgsmaptoolidentifyfeature.cpp:47
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMapTool::mCursor
QCursor mCursor
cursor used in map tool
Definition: qgsmaptool.h:267
QgsMapMouseEvent
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Definition: qgsmapmouseevent.h:36
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:387
QgsMapCanvas::unsetMapTool
void unsetMapTool(QgsMapTool *mapTool)
Unset the current map tool or last non zoom tool.
Definition: qgsmapcanvas.cpp:2046
QgsMapToolIdentify::identifyVectorLayer
bool identifyVectorLayer(QList< QgsMapToolIdentify::IdentifyResult > *results, QgsVectorLayer *layer, const QgsPointXY &point)
Definition: qgsmaptoolidentify.cpp:238
QgsMapToolIdentifyFeature::featureIdentified
void featureIdentified(const QgsFeature &)
qgsmapmouseevent.h
QgsMapTool::mToolName
QString mToolName
translated name of the map tool
Definition: qgsmaptool.h:282